javacpp-presets icon indicating copy to clipboard operation
javacpp-presets copied to clipboard

Conflict between JavaCV 1.5.7-snapshot and Depthai-2.13.3-1.5.7-snapshot

Open wureka opened this issue 2 years ago • 32 comments

Environment:

  • OS: Zorin OS 16 Pro (based on Ubuntu 20.04 LTS 64bit)
  • JDK: GraalVM 21.3.0-R11
  • Javacpp-presets: 1.5.7-snapshot
    • depthai: 2.13.3
    • opencv: 4.5.5
    • openblas: 0.3.19
  • JavaCV: 1.5.7-snapshot

Test code:

It seems that JavaCV has something conflicts with Depthai in this version. But this did not happen in the old version (JavaCV 1.5.5 vs Depthai 2.5.x, 2.6.x)

If I use imshow of opencv to show the grabbed images from OAK-D camera, everything is fine.

However, if I use CanvasFrame of JavaCV to show the grabbed image, below errors will happen:

MX ID:14442C102176E1D200
Check point 00001----------------
Detect org.bytedeco.javacpp.IntPointer[address=0x7f5245d36ab0,position=0,limit=3,capacity=3,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f5245d36ab0,deallocatorAddress=0x7f505f98e3c0]] camera(s) 
Check point 00002----------------
USB speed: SUPER 
Check point 00003----------------
    Camera 0 is ready!
    Camera 1 is ready!
    Camera 2 is ready!
Check point 00004----------------
Initialize JavaCV converter
Initialize JavaCV CanvasFrame
Stack trace (most recent call last) in thread 19662:
#0    Object "[0x7f52311d5595]", at 0x7f52311d5595, in 
Segmentation fault (Address not mapped to object [0x8])

The above error happens on below line (line 73 in Demo.java in test code):

videoCanvas = new CanvasFrame("Preview", 1.0);

If test only JavaCV without involving depthai, JavaCV works fine.

    public static void main(String[] args) throws Exception {
        // demoJavaCv();             // uncomment this line will test JavaCV only.
        demoDepthaiRgbPreview();
    }

wureka avatar Jan 10 '22 23:01 wureka

It might be your video driver not supporting OpenGL properly. Make sure OpenGL support in Java 2D is disabled.

saudet avatar Jan 11 '22 00:01 saudet

Also, if you don't need to use Java 2D, I would recommend using JavaFX instead: https://github.com/rladstaetter/javacv-webcam And before you ask, it would be nice to have an "FXCanvasFrame", yes, contributions are welcome...

/cc @rladstaetter @johanvos

saudet avatar Jan 11 '22 02:01 saudet

Moreover, DepthAI 2.14.0 has been released and the presets upgraded in commit https://github.com/bytedeco/javacpp-presets/commit/9dd400b9bfd7387db95994dae0c00e185f307994, so you might want to try that as well.

saudet avatar Jan 11 '22 03:01 saudet

Just tried DepthAI 2.14.0 and added below property to main function:

System.setProperty("sun.java2d.opengl", "false");
System.setProperty("sun.java2d.xrender", "false");

still not work.

wureka avatar Jan 11 '22 07:01 wureka

Does it do anything different if you set the "org.bytedeco.javacpp.nopointergc" system property to "true"?

saudet avatar Jan 11 '22 07:01 saudet

Also, try to set the "org.bytedeco.javacpp.logger.debug" system property to "true", and let me know what you get on the console. I might be able to see something going wrong there from that log.

saudet avatar Jan 13 '22 07:01 saudet

OK. After I add System.setProperty("org.bytedeco.javacpp.logger.debug", "true");, below are the debug messages:

> Task :Demo.main()
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.javacpp.Loader
Debug: Loading /home/alexji/.javacpp/cache/javacpp-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/javacpp/linux-x86_64/libjnijavacpp.so
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.javacpp.Pointer
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading /home/alexji/.javacpp/cache/openblas-0.3.19-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/openblas/linux-x86_64/libgcc_s.so.1
Debug: Loading /home/alexji/.javacpp/cache/openblas-0.3.19-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/openblas/linux-x86_64/libquadmath.so.0
Debug: Loading /home/alexji/.javacpp/cache/openblas-0.3.19-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/openblas/linux-x86_64/libgfortran.so.5
Debug: Loading library gfortran
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no gfortran in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library gfortran
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no gfortran in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading /home/alexji/.javacpp/cache/openblas-0.3.19-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/openblas/linux-x86_64/libopenblas_nolapack.so.0
Debug: Loading /home/alexji/.javacpp/cache/openblas-0.3.19-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/openblas/linux-x86_64/libjniopenblas_nolapack.so
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading /home/alexji/.javacpp/cache/openblas-0.3.19-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/openblas/linux-x86_64/libopenblas.so.0
Debug: Loading /home/alexji/.javacpp/cache/openblas-0.3.19-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/openblas/linux-x86_64/libjniopenblas.so
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading library cudart
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cudart in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library cublasLt
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cublasLt in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library cublas
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cublas in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library cufft
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cufft in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library cudnn
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cudnn in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppc
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppc in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppial
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppial in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppicc
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppicc in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppicom
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppicom in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppidei
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppidei in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppif
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppif in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppig
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppig in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppim
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppim in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppist
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppist in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppisu
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppisu in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppitc
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppitc in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library npps
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no npps in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library cudnn_ops_infer
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cudnn_ops_infer in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library cudnn_ops_train
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cudnn_ops_train in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library cudnn_adv_infer
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cudnn_adv_infer in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library cudnn_adv_train
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cudnn_adv_train in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library cudnn_cnn_infer
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cudnn_cnn_infer in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library cudnn_cnn_train
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cudnn_cnn_train in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library opencv_cudev
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no opencv_cudev in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading /home/alexji/.javacpp/cache/opencv-4.5.5-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/opencv/linux-x86_64/libopencv_core.so.405
Debug: Loading /home/alexji/.javacpp/cache/opencv-4.5.5-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/opencv/linux-x86_64/libopencv_imgproc.so.405
Debug: Loading /home/alexji/.javacpp/cache/opencv-4.5.5-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/opencv/linux-x86_64/libjniopencv_core.so
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.opencv_core.CvSlice
Debug: Registering org.bytedeco.opencv.opencv_core.CvSlice[address=0x7fd7c89995c0,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7fd7c89995c0,deallocatorAddress=0x7fd618abebc0]]
Debug: Registering org.bytedeco.opencv.opencv_core.CvSlice[address=0x7fd7c8a0ec70,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7fd7c8a0ec70,deallocatorAddress=0x7fd618abebc0]]
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading /home/alexji/.javacpp/cache/opencv-4.5.5-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/opencv/linux-x86_64/libjniopencv_imgproc.so
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading /home/alexji/.javacpp/cache/depthai-2.14.0-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/depthai/linux-x86_64/libdepthai-core.so
Debug: Loading /home/alexji/.javacpp/cache/depthai-2.14.0-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/depthai/linux-x86_64/libdepthai-opencv.so
Debug: Loading /home/alexji/.javacpp/cache/depthai-2.14.0-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/depthai/linux-x86_64/libjnidepthai.so
Debug: Loading class org.bytedeco.depthai.Pipeline
Debug: Registering org.bytedeco.depthai.Pipeline[address=0x7fd7c898bf80,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7fd7c898bf80,deallocatorAddress=0x7fd61858b240]]
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.Node
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.ColorCameraPropertiesNode
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.ColorCamera
Debug: Registering org.bytedeco.depthai.ColorCamera[address=0x7fd7c8a0db10,position=0,limit=0,capacity=0,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7fd7c8abb310,deallocatorAddress=0x7fd6186bb8c0]]
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.XLinkOutPropertiesNode
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.XLinkOut
Debug: Registering org.bytedeco.depthai.XLinkOut[address=0x7fd7c8a1cc10,position=0,limit=0,capacity=0,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7fd7c8a21460,deallocatorAddress=0x7fd6186bb6e0]]
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.Node$Output
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.Node$Input
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.DeviceBase
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.Device
Debug: Registering org.bytedeco.depthai.Device[address=0x7fd7c8a21e10,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7fd7c8a21e10,deallocatorAddress=0x7fd618582670]]
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.javacpp.BytePointer
Debug: Registering org.bytedeco.javacpp.BytePointer[address=0x7fd7c8a21cb0,position=0,limit=18,capacity=18,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7fd7c8a21cb0,deallocatorAddress=0x7fd6186b7ca0]]
MX ID:18443010D105A41200
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.javacpp.IntPointer
Debug: Registering org.bytedeco.javacpp.IntPointer[address=0x7fd7c9e92de0,position=0,limit=3,capacity=3,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7fd7c9e92de0,deallocatorAddress=0x7fd6186b7550]]
Check point 00001----------------
Detect org.bytedeco.javacpp.IntPointer[address=0x7fd7c9e92de0,position=0,limit=3,capacity=3,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7fd7c9e92de0,deallocatorAddress=0x7fd6186b7550]] camera(s) 
Check point 00002----------------
USB speed: SUPER 
Check point 00003----------------
    Camera 0 is ready!
    Camera 1 is ready!
    Camera 2 is ready!
Check point 00004----------------
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.DataOutputQueue
Debug: Registering org.bytedeco.depthai.DataOutputQueue[address=0x7fd7c8a220a0,position=0,limit=0,capacity=0,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7fd7c9e91280,deallocatorAddress=0x7fd6186bb1e0]]Initialize JavaCV converter

Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Initialize JavaCV CanvasFrame
Debug: Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7fd7c8a21cb0,deallocatorAddress=0x7fd6186b7ca0]
Stack trace (most recent call last) in thread 23032:
#0    Object "[0x7fd7b11e91ff]", at 0x7fd7b11e91ff, in 
Segmentation fault (Invalid permissions for mapped object [0x7fd7ceafa008])

> Task :Demo.main() FAILED

Execution failed for task ':Demo.main()'.
> Process 'command '/home/alexji/.sdkman/candidates/java/11.0.12-open/bin/java'' finished with non-zero exit value 139

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

The weird thing is that, if I change the initialization of JavaCanvas to front of new Pipeline(), sometime the code can work and keeps running for about 1 minute then crashes.

Original code:

    static void demoDepthaiRgbPreview() {
        OpenCVFrameConverter.ToMat converter = null;
        CanvasFrame videoCanvas = null;


        Pipeline pipeline  = new Pipeline();

        ColorCamera camRgb = pipeline.createColorCamera();
        XLinkOut xoutRgb   = pipeline.createXLinkOut();

        xoutRgb.setStreamName("rgb");
        camRgb.setResolution(ColorCameraProperties.SensorResolution.THE_1080_P);
        camRgb.setPreviewSize(WIDTH, HEIGHT);
        camRgb.setInterleaved(INTERLEAVED);
        camRgb.setColorOrder(ColorCameraProperties.ColorOrder.BGR);

        camRgb.preview().link(xoutRgb.input());

        Device device = new Device();
        System.out.println("MX ID:" + device.getMxId().getString());
        device.startPipeline(pipeline);
        IntPointer cameras = device.getConnectedCameras();
        System.out.println("Check point 00001----------------");

        System.out.printf("Detect %s camera(s) \n", cameras);
        System.out.println("Check point 00002----------------");
        System.out.printf("USB speed: %s \n", device.getUsbSpeed());
        System.out.println("Check point 00003----------------");
        for (int i = 0; i < cameras.limit(); i++) {
            System.out.printf("    Camera %d is ready!\n", cameras.get(i));
        }
        System.out.println("Check point 00004----------------");
        DataOutputQueue qRgb = device.getOutputQueue("rgb", 4, false);

        // move below if block to upper position. And sometime the code can keep working for 1 minutes
        if (useJavaCvCanvasFrame) {
            System.out.println("Initialize JavaCV converter");
            converter = new OpenCVFrameConverter.ToMat();
            System.out.println("Initialize JavaCV CanvasFrame");
//            TODO: Below will happen errors
//            Stack trace (most recent call last) in thread 23203:
//            #0    Object "[0x7f4707eb10f5]", at 0x7f4707eb10f5, in
//            Segmentation fault (Address not mapped to object [0x8])
            videoCanvas = new CanvasFrame("JavaCV Preview", 1.0);
        }

        Mat opencvMat;
        long time0 = 0, time1 = 0, accumConvertTime = 0;
        int count = 0;
        final int TOTAL_FRAME_COUNT = 1000;

After changed:

   static void demoDepthaiRgbPreview() {
        OpenCVFrameConverter.ToMat converter = null;
        CanvasFrame videoCanvas = null;

        if (useJavaCvCanvasFrame) {
            System.out.println("Initialize JavaCV converter");
            converter = new OpenCVFrameConverter.ToMat();
            System.out.println("Initialize JavaCV CanvasFrame");
//            TODO: Below will happen errors
//            Stack trace (most recent call last) in thread 23203:
//            #0    Object "[0x7f4707eb10f5]", at 0x7f4707eb10f5, in
//            Segmentation fault (Address not mapped to object [0x8])
            videoCanvas = new CanvasFrame("JavaCV Preview", 1.0);
        }

        
        Pipeline pipeline  = new Pipeline();

        ColorCamera camRgb = pipeline.createColorCamera();
        XLinkOut xoutRgb   = pipeline.createXLinkOut();

        xoutRgb.setStreamName("rgb");
        camRgb.setResolution(ColorCameraProperties.SensorResolution.THE_1080_P);
        camRgb.setPreviewSize(WIDTH, HEIGHT);
        camRgb.setInterleaved(INTERLEAVED);
        camRgb.setColorOrder(ColorCameraProperties.ColorOrder.BGR);

        camRgb.preview().link(xoutRgb.input());

        Device device = new Device();
        System.out.println("MX ID:" + device.getMxId().getString());
        device.startPipeline(pipeline);
        IntPointer cameras = device.getConnectedCameras();
        System.out.println("Check point 00001----------------");

        System.out.printf("Detect %s camera(s) \n", cameras);
        System.out.println("Check point 00002----------------");
        System.out.printf("USB speed: %s \n", device.getUsbSpeed());
        System.out.println("Check point 00003----------------");
        for (int i = 0; i < cameras.limit(); i++) {
            System.out.printf("    Camera %d is ready!\n", cameras.get(i));
        }
        System.out.println("Check point 00004----------------");
        DataOutputQueue qRgb = device.getOutputQueue("rgb", 4, false);


        Mat opencvMat;
        long time0 = 0, time1 = 0, accumConvertTime = 0;
        int count = 0;
        final int TOTAL_FRAME_COUNT = 1000;

Debug messages aftere code changed

> Task :Demo.main()
Initialize JavaCV converter
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.javacpp.Loader
Debug: Loading /home/alexji/.javacpp/cache/javacpp-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/javacpp/linux-x86_64/libjnijavacpp.so
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.javacpp.Pointer
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading /home/alexji/.javacpp/cache/openblas-0.3.19-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/openblas/linux-x86_64/libgcc_s.so.1
Debug: Loading /home/alexji/.javacpp/cache/openblas-0.3.19-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/openblas/linux-x86_64/libquadmath.so.0
Debug: Loading /home/alexji/.javacpp/cache/openblas-0.3.19-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/openblas/linux-x86_64/libgfortran.so.5
Debug: Loading library gfortran
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no gfortran in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library gfortran
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no gfortran in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading /home/alexji/.javacpp/cache/openblas-0.3.19-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/openblas/linux-x86_64/libopenblas_nolapack.so.0
Debug: Loading /home/alexji/.javacpp/cache/openblas-0.3.19-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/openblas/linux-x86_64/libjniopenblas_nolapack.so
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading /home/alexji/.javacpp/cache/openblas-0.3.19-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/openblas/linux-x86_64/libopenblas.so.0
Debug: Loading /home/alexji/.javacpp/cache/openblas-0.3.19-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/openblas/linux-x86_64/libjniopenblas.so
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading library cudart
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cudart in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library cublasLt
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cublasLt in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library cublas
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cublas in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library cufft
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cufft in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library cudnn
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cudnn in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppc
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppc in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppial
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppial in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppicc
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppicc in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppicom
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppicom in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppidei
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppidei in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppif
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppif in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppig
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppig in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppim
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppim in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppist
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppist in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppisu
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppisu in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library nppitc
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no nppitc in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library npps
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no npps in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library cudnn_ops_infer
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cudnn_ops_infer in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library cudnn_ops_train
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cudnn_ops_train in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library cudnn_adv_infer
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cudnn_adv_infer in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library cudnn_adv_train
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cudnn_adv_train in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library cudnn_cnn_infer
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cudnn_cnn_infer in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library cudnn_cnn_train
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no cudnn_cnn_train in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading library opencv_cudev
Debug: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: no opencv_cudev in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
Debug: Loading /home/alexji/.javacpp/cache/opencv-4.5.5-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/opencv/linux-x86_64/libopencv_core.so.405
Debug: Loading /home/alexji/.javacpp/cache/opencv-4.5.5-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/opencv/linux-x86_64/libopencv_imgproc.so.405
Debug: Loading /home/alexji/.javacpp/cache/opencv-4.5.5-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/opencv/linux-x86_64/libjniopencv_core.so
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.opencv_core.CvSlice
Debug: Registering org.bytedeco.opencv.opencv_core.CvSlice[address=0x7f8264994160,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f8264994160,deallocatorAddress=0x7f80b627bbc0]]
Debug: Registering org.bytedeco.opencv.opencv_core.CvSlice[address=0x7f82649dc9e0,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f82649dc9e0,deallocatorAddress=0x7f80b627bbc0]]
Initialize JavaCV CanvasFrame
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading /home/alexji/.javacpp/cache/opencv-4.5.5-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/opencv/linux-x86_64/libjniopencv_imgproc.so
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading /home/alexji/.javacpp/cache/depthai-2.14.0-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/depthai/linux-x86_64/libdepthai-core.so
Debug: Loading /home/alexji/.javacpp/cache/depthai-2.14.0-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/depthai/linux-x86_64/libdepthai-opencv.so
Debug: Loading /home/alexji/.javacpp/cache/depthai-2.14.0-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/depthai/linux-x86_64/libjnidepthai.so
Debug: Loading class org.bytedeco.depthai.Pipeline
Debug: Registering org.bytedeco.depthai.Pipeline[address=0x7f8264af0270,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f8264af0270,deallocatorAddress=0x7f80b1142240]]
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.Node
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.ColorCameraPropertiesNode
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.ColorCamera
Debug: Registering org.bytedeco.depthai.ColorCamera[address=0x7f82649d7500,position=0,limit=0,capacity=0,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f8264c08be0,deallocatorAddress=0x7f80b12728c0]]
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.XLinkOutPropertiesNode
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.XLinkOut
Debug: Registering org.bytedeco.depthai.XLinkOut[address=0x7f8264a9ba60,position=0,limit=0,capacity=0,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f8264c0a1a0,deallocatorAddress=0x7f80b12726e0]]
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.Node$Output
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.Node$Input
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.DeviceBase
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.Device
Debug: Registering org.bytedeco.depthai.Device[address=0x7f8264c09860,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f8264c09860,deallocatorAddress=0x7f80b1139670]]
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.javacpp.BytePointer
Debug: Registering org.bytedeco.javacpp.BytePointer[address=0x7f8264c09b10,position=0,limit=18,capacity=18,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f8264c09b10,deallocatorAddress=0x7f80b126eca0]]
MX ID:18443010D105A41200
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.javacpp.IntPointer
Debug: Registering org.bytedeco.javacpp.IntPointer[address=0x7f8265fd71e0,position=0,limit=3,capacity=3,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f8265fd71e0,deallocatorAddress=0x7f80b126e550]]
Check point 00001----------------
Detect org.bytedeco.javacpp.IntPointer[address=0x7f8265fd71e0,position=0,limit=3,capacity=3,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f8265fd71e0,deallocatorAddress=0x7f80b126e550]] camera(s) 
Check point 00002----------------
USB speed: SUPER 
Check point 00003----------------
    Camera 0 is ready!
    Camera 1 is ready!
    Camera 2 is ready!
Check point 00004----------------
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.DataOutputQueue
Debug: Registering org.bytedeco.depthai.DataOutputQueue[address=0x7f8264adac60,position=0,limit=0,capacity=0,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f8264b8be20,deallocatorAddress=0x7f80b12721e0]]
Ready to show grabbed frames .....
Debug: Opening org.bytedeco.javacpp.PointerScope@42e25b0b
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.ADatatype
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.Buffer
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.depthai.global.depthai
Debug: Loading class org.bytedeco.depthai.ImgFrame
Debug: Registering org.bytedeco.depthai.ImgFrame[address=0x7f80900010f0,position=0,limit=0,capacity=0,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f8265fd45c0,deallocatorAddress=0x7f80b12737c0]]
Debug: Attaching org.bytedeco.depthai.ImgFrame[address=0x7f80900010f0,position=0,limit=0,capacity=0,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f8265fd45c0,deallocatorAddress=0x7f80b12737c0]] to org.bytedeco.javacpp.PointerScope@42e25b0b
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.opencv_core.AbstractArray
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.opencv_core.Mat
Debug: Registering org.bytedeco.opencv.opencv_core.Mat[width=416,height=416,depth=8,channels=3]
Debug: Attaching org.bytedeco.opencv.opencv_core.Mat[width=416,height=416,depth=8,channels=3] to org.bytedeco.javacpp.PointerScope@42e25b0b
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.opencv.global.opencv_imgcodecs
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.opencv.global.opencv_imgcodecs
Debug: Loading /home/alexji/.javacpp/cache/opencv-4.5.5-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/opencv/linux-x86_64/libopencv_imgcodecs.so.405
Debug: Loading /home/alexji/.javacpp/cache/opencv-4.5.5-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/opencv/linux-x86_64/libjniopencv_imgcodecs.so
Debug: Loading class org.bytedeco.opencv.global.opencv_videoio
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.openblas.global.openblas_nolapack
Debug: Loading class org.bytedeco.openblas.global.openblas
Debug: Loading class org.bytedeco.opencv.global.opencv_core
Debug: Loading class org.bytedeco.opencv.global.opencv_imgproc
Debug: Loading class org.bytedeco.opencv.global.opencv_imgcodecs
Debug: Loading class org.bytedeco.opencv.global.opencv_videoio
Debug: Loading /home/alexji/.javacpp/cache/opencv-4.5.5-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/opencv/linux-x86_64/libopencv_videoio.so.405
Debug: Loading /home/alexji/.javacpp/cache/opencv-4.5.5-1.5.7-SNAPSHOT-linux-x86_64.jar/org/bytedeco/opencv/linux-x86_64/libjniopencv_videoio.so
Debug: Loading class org.bytedeco.opencv.global.opencv_highgui

wureka avatar Jan 13 '22 09:01 wureka

Debug: Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7fd7c8a21cb0,deallocatorAddress=0x7fd6186b7ca0]

That pops up just before the crash, so this pointer is probably getting deallocated prematurely. Make sure that doesn't happen.

saudet avatar Jan 13 '22 10:01 saudet

Any solution or workaround to this? I experience a similar issue on OSX and Ubuntu using version 1.5.7. Grabbing stops after some minutes at

imgFrame = queue.getImgFrame(); imgFrame.getData().asByteBuffer().get(imageData);

with this log:

Debug: Registering org.bytedeco.depthai.ImgFrame[address=0x600001c0f658,position=0,limit=0,capacity=0,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x600000ad4380,deallocatorAddress=0x145bde850]]
Debug: Registering org.bytedeco.javacpp.BytePointer[address=0x7fc4c4b70000,position=0,limit=921600,capacity=921600,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7fc4c4b70000,deallocatorAddress=0x145b9a200]]
Stack trace (most recent call last):
#2    Object "libsystem_platform.dylib", at 0x7ff81c676e2c, in _sigtramp + 28
#1    Object "libdepthai-core.dylib", at 0x16414016d, in backward::SignalHandling::sig_handler(int, __siginfo*, void*) + 13
#0    Object "libdepthai-core.dylib", at 0x1641401dc, in backward::SignalHandling::sig_handler(int, __siginfo*, void*) + 124

ecmnet avatar Feb 10 '22 07:02 ecmnet

@ecmnet Please try to set the "org.bytedeco.javacpp.nopointergc" system property to "true" and see if that helps.

saudet avatar Feb 10 '22 07:02 saudet

@saudet Unfortunately not - I see that in this case neither registering nor GC takes place. Python and C++ DepthAI examples work.

Debug: Loading class org.bytedeco.javacpp.BytePointer Stack trace (most recent call last): #2 Object "libsystem_platform.dylib", at 0x7ff81c676e2c, in _sigtramp + 28 #1 Object "libdepthai-core.dylib", at 0x16056b16d, in backward::SignalHandling::sig_handler(int, __siginfo*, void*) + 13 #0 Object "libdepthai-core.dylib", at 0x16056b1dc, in backward::SignalHandling::sig_handler(int, __siginfo*, void*) + 124

ecmnet avatar Feb 10 '22 07:02 ecmnet

Ok, thanks for testing. If DepthAI uses signal handlers, you'll need to do some signal chaining: https://docs.oracle.com/javase/9/vm/signal-chaining.htm @themarpe Do you know if DepthAI relies on signal handlers?

saudet avatar Feb 10 '22 08:02 saudet

@saudet I tried using the -Xrs option as well as the environment variable settings as described in the document above. Both with no success.

ecmnet avatar Feb 10 '22 08:02 ecmnet

It's possible DepthAI becomes unstable when we don't immediately release all memory that it returns to us. For example, make sure close() gets called on the object that getImgFrame() returns, but also on other objects too. This can more easily be done with a PointerScope: http://bytedeco.org/news/2018/07/17/bytedeco-as-distribution/

saudet avatar Feb 10 '22 08:02 saudet

@saudet Tried that also in different ways - even doing it step by step closing all objects immediately does not work.

Debug: Registering org.bytedeco.depthai.ImgFrame[address=0x600002f58f18,position=0,limit=0,capacity=0,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x60000389dcf0,deallocatorAddress=0x136d5a850]] Debug: Registering org.bytedeco.depthai.RawBuffer[address=0x600000889cc8,position=0,limit=0,capacity=0,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x60000389fc50,deallocatorAddress=0x136d13d50]] Debug: Releasing org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x60000389dcf0,deallocatorAddress=0x136d5a850] Debug: Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Debug: Registering org.bytedeco.javacpp.BytePointer[address=0x7f8948008000,position=0,limit=921600,capacity=921600,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f8948008000,deallocatorAddress=0x136d16200]] Debug: Releasing org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x60000389fc50,deallocatorAddress=0x136d13d50] Debug: Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Debug: Releasing org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f8948008000,deallocatorAddress=0x136d16200] Debug: Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x0,deallocatorAddress=0x0] Stack trace (most recent call last): #2 Object "libsystem_platform.dylib", at 0x7ff81c676e2c, in _sigtramp + 28 #1 Object "libdepthai-core.dylib", at 0x15537a16d, in backward::SignalHandling::sig_handler(int, __siginfo*, void*) + 13 #0 Object "libdepthai-core.dylib", at 0x15537a1dc, in backward::SignalHandling::sig_handler(int, __siginfo*, void*) + 124

ecmnet avatar Feb 10 '22 08:02 ecmnet

An additional observation: Grabbing lives longer (up to 3 mins), when closing each object immediately and using PointerScope enclosing all statements.

ecmnet avatar Feb 10 '22 08:02 ecmnet

If you still see "Collecting" with an address other than 0 in the log, that means it's not getting deallocated explicitly. Find where they come from, or use additional PointerScope blocks, and make sure to close them as quickly as possible.

saudet avatar Feb 10 '22 10:02 saudet

Weird. Meanwhile I use a callback to grab the frames, which seems to work as long as I do not have an AnimationTimer (to update the Java FXImage) - I even copied the grabbed array - but as soon as I enable the timer, grabbing stops:


               @Override
		public void call() {
			try (PointerScope scope = new PointerScope()) {	
				ImgFrame imgFrame = preview.getImgFrame();
				imgFrame.getData().asBuffer().get(buffer1);
				System.arraycopy(buffer1, 0, buffer2, 0, buffer1.length);
				imgFrame.close();
			}
		}
                      output = new BufferedImage(width,height, BufferedImage.TYPE_3BYTE_BGR);
		      buffer2 = ((DataBufferByte) output.getRaster().getDataBuffer()).getData();
		      buffer1 = new byte[imageData.length];
                      ...
                       task = new AnimationTimer() {
			@Override
			public void handle(long now) {
				Platform.runLater(() -> {
					SwingFXUtils.toFXImage(output, wirgb);
				});

			}
		};

ecmnet avatar Feb 10 '22 11:02 ecmnet

DepthAI may not be entirely thread-safe, don't try to make calls from multiple threads.

saudet avatar Feb 10 '22 12:02 saudet

It does register some signal handlers for use with Backward - crash stack printer. Can be disabled by setting DEPTHAI_INSTALL_SIGNAL_HANDLER=0 or by compiling without Backward enabled (we might tweak the built scripts for this to be the default for Java binding builds)

Ps: Can be disabled when compiling by setting CMake define -D DEPTHAI_ENABLE_BACKWARD=OFF

themarpe avatar Feb 10 '22 12:02 themarpe

@saudet @themarpe Seems to work now by

  • disabling the signal handler and
  • converting the BufferedImage to the FX WritableImage within the callback

So I assume, there were two root causes: Threading and signal-handling.

		@Override
		public void call() {
			try (PointerScope scope = new PointerScope()) {	
				ImgFrame imgFrame = preview.getImgFrame();
				imgFrame.getData().asBuffer().get(buffer);
				imgFrame.close();
			}
                       SwingFXUtils.toFXImage(output, wirgb);
		}

Thanks a lot for your support.

ecmnet avatar Feb 10 '22 13:02 ecmnet

@saudet: While this is working now properly with OSX, I receive now the issue as described by @wureka with Ubuntu. I am not using any java 2D functionalities.

Debug: Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7fd4f81cd480,deallocatorAddress=0x7fd47e1ec610]
Debug: Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7fd4f81cd460,deallocatorAddress=0x7fd47e1f00b0]
Debug: Collecting org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7fd4f81d1f40,deallocatorAddress=0x7fd47e0c1ac0]
[2022-02-11 09:19:37.271] [error] Callback with id: 1 throwed an exception: java.lang.NullPointerException
Stack trace (most recent call last) in thread 6718:
#0    Object "[0x7fd4e1774777]", at 0x7fd4e1774777, in 
Speicherzugriffsfehler (Ingültige Rechte für das "mapped Object" [0x7fd476b9cfe0])
Speicherzugriffsfehler

Obviously still a deallocation issue there. The debug output shows 'Collecting' with addresses !=0 for objects that were not allocated (at least do not show up in the debug output). I assumed, this should be the case.

ecmnet avatar Feb 11 '22 08:02 ecmnet

Right, you'll probably need to get rid of those "Collecting" lines. You could set the "org.bytedeco.javacpp.nopointergc" system property, but as discussed above, that would likely result in memory leaks, and could also make DepthAI unstable. You'll need to figure out where those objects are and close them as soon as they are not needed anymore, or try to use PointerScope blocks as necessary.

saudet avatar Feb 11 '22 12:02 saudet

@saudet, @themarpe After cleaning up, the crash did not appear anymore in the context of 'Collecting'. But still it does not work. It happens (after a couple of seconds) as soon as I place

Pipeline p = new Pipeline()

into the code - no other DepthAI-related code is involved (even no 'device'). Closing it soon or surrounding it by PointerScope does not help. The object mentioned in the dump does not appear in the java context at all. Note, that this is Ubuntu only - OSX runs fine.

ecmnet avatar Feb 14 '22 12:02 ecmnet

Maybe we need to make sure the Pipeline stays alive? Try to close at a later point in time.

saudet avatar Feb 14 '22 13:02 saudet

No chance - I got it working slightly longer (about 800 frames), but all cases ended with a crash.

ecmnet avatar Feb 14 '22 15:02 ecmnet

With signal handler and backward disabled, everything on a signal thread? That reminds me, the JDK doesn't run the main thread on the first thread of the process. It is possible DepthAI doesn't like that.

saudet avatar Feb 14 '22 21:02 saudet

@saudet @themarpe After carefully redesigning the code, using blocking queues, etc, I managed to get DepthAI running on Ubuntu for a couple of minutes, but far from stable. The same code runs smoothly for hours on OSX. However, I saw a multihreading-related branch on DepthAI side - maybe that helps in future. Currently I consider DepthAI not usable on Ubuntu with Java.

ecmnet avatar Feb 15 '22 18:02 ecmnet

@Grumpy141 @ecmnet @wureka I've disabled the signal handlers in commit https://github.com/bytedeco/javacpp-presets/commit/5ac61a83a69c05fe7f71e88d6614598101e4b2da, please give it a try with the snapshots: https://oss.sonatype.org/content/repositories/snapshots/org/bytedeco/depthai/2.14.1-1.5.8-SNAPSHOT/ Just to be extra sure DepthAI doesn't try to install them anyway, please also make sure to set the "DEPTHAI_INSTALL_SIGNAL_HANDLER" environment variable to "0".

saudet avatar Feb 17 '22 00:02 saudet

This fixed my issue.  2.14.1 is stable now, both on Mac O/S and Linux armhf I didn't have to set the environment variable.

On Wednesday, February 16, 2022, 05:46:55 PM MST, Samuel Audet ***@***.***> wrote:  

@Grumpy141 @ecmnet @wureka I've disabled the signal handlers in commit 5ac61a8, please give it a try with the snapshots: https://oss.sonatype.org/content/repositories/snapshots/org/bytedeco/depthai/2.14.1-1.5.8-SNAPSHOT/ Just to be extra sure DepthAI doesn't try to install them anyway, please also make sure to set the "DEPTHAI_INSTALL_SIGNAL_HANDLER" environment variable to "0".

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.Message ID: @.***>

Grumpy141 avatar Feb 17 '22 01:02 Grumpy141