clEsperanto / clesperantoj_prototype

A Java Wrapper around CLIc / clesperanto
4 stars 3 forks source link

JavaCPP does not seems to allow `null` to be passed instead of a ptr. #41

Closed StRigaud closed 2 months ago

StRigaud commented 2 months ago
Tier1.absolute(currentDevice, input, output);

is fine but

ArrayJ output = Tier1.absolute(currentDevice, input, null);

raise an error:

Exception in thread "main" java.lang.NullPointerException: Pointer address of argument 2 is NULL.
        at net.clesperanto._internals.kernelj$Tier1.absolute(Native Method)
        at net.clesperanto.kernels.Tier1.absolute(Tier1.java:66)
        at net.clesperanto.Imglib2ClesperantoJExample.main(Imglib2ClesperantoJExample.java:37)
StRigaud commented 2 months ago

I think this is related to how the function is define in the native part:

static ArrayJ absolute(const DeviceJ &dev, const ArrayJ &src, ArrayJ &dst);

ArrayJ parameters are passed as ref, hence cannot be null, we should update the function to take ptr.

We would need to rewrite it as followed:

static ArrayJ Tier1::absolute( DeviceJ* dev,  ArrayJ* src, ArrayJ* dst)

and add a check for nullptr inside the cpp code

Doing so seems to work.

StRigaud commented 2 months ago

Solved by #42