Repository metrics
- Stars
- (4,279 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
Hello,
I'm writing an interface to a mipi camera and have written a c++ facade over the mipi driver to simplify the calling and then compiled this into a jar with JavaCPP. The java class is as follows:
package com.ziath.ardugrab;
import org.bytedeco.javacpp.Loader;
import org.bytedeco.javacpp.Pointer;
import org.bytedeco.javacpp.annotation.Namespace;
import org.bytedeco.javacpp.annotation.Platform;
@Platform(link = {"arducam_mipicamera", "ardugrab"}, include= {"ardugrab.h","arducam_mipicamera.h"})
@Namespace("ArduGrabLibrary")
public class ArduGrab extends Pointer {
static {Loader.load();}
public static int DEFAULT_EXPOSURE = 1500;
public static int DEFAULT_FOCUS = 400;
public static int DEFAULT_WIDTH = 4656;
public static int DEFAULT_HEIGHT = 3496;
public static int CAMERA_NOT_CONNECTED = -1303;
public ArduGrab() {allocate();}
private native void allocate();
public native int initCamera();
public native int closeCamera();
public native void setSim(boolean sim);
public native void setDebug(boolean debug);
public native int setExposure(int exposure);
public native int getExposure();
public native int setFocus(int focus);
public native int getFocus();
public native int setResolution(int width, int height);
public native int getResolutionWidth();
public native int getResolutionHeight();
}
I'm then testing the underlying native sharedlibrary with the following code:
#include "ardugrab.h"
using namespace ArduGrabLibrary;
int main() {
ArduGrab* ag = new ArduGrab();
ag->setDebug(true);
ag->setSim(false);
ag->initCamera();
ag->setExposure(3000);
ag->setFocus(600);
ag->setResolution(4656, 3496);
ag->closeCamera();
return 0;
}
I can execute this 1,000 times with no problem. However I've got the same thing runnign through JavaCPP:
import com.ziath.ardugrab.ArduGrab;
public class TestArduGrab {
public static void main(String args[]) {
ArduGrab ag = new ArduGrab();
ag.setDebug(true);
ag.setSim(false);
ag.initCamera();
ag.setExposure(3000);
ag.setFocus(600);
ag.setResolution(4656, 3496);
ag.closeCamera();
ag.close();
}
}
This gives me either segmentation faults or a JVM crash about 1 in 5 times. I'm not sure how to go about testing this as there is clearly something when running through the generated jar from JavaCPP which is causing me an issue. Can you provide any tips as to how to start looking into this. I note that if I remove the calls to the underlying mipi driver library, this does not happen so it is somethign to do with refencing the third party library so I need to understand the environment when running though JavaCPP and 'raw' native code to determine why I'm getting seg faults.
I understand that this is very specific to our case, if required I would be more than happy to pay for any assistance as I'm sure you get this kind of question - a lot!
Thanks.
Regards,
Neil