Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java JNI wrapper oniFrameRelease and oniStreamReadFrame issues #60

Open
benbryan opened this issue Jul 29, 2015 · 2 comments
Open

java JNI wrapper oniFrameRelease and oniStreamReadFrame issues #60

benbryan opened this issue Jul 29, 2015 · 2 comments

Comments

@benbryan
Copy link

oniStreamReadFrame returns a ByteBuffer pointing to volatile memory. To fix this I returned a byte[] by changing
jobject buffer = env->NewDirectByteBuffer(pOniFrame->data, pOniFrame->dataSize);
fieldID = env->GetFieldID(videoFrameRefCls, "mData", "Ljava/nio/ByteBuffer;");
env->SetObjectField(videoFrameRefObj,fieldID, buffer);
to
jbyteArray buffer = env->NewByteArray(pOniFrame->dataSize);
env->SetByteArrayRegion(buffer, 0, pOniFrame->dataSize, (jbyte*) pOniFrame->data);
fieldID = env->GetFieldID(videoFrameRefCls, "mData", "[B");
env->SetObjectField(videoFrameRefObj, fieldID, buffer);
and made the mData field a byte[] in java.

The end oniStreamReadFrame calls oniFrameRelease. Calling this function again from java causes a fatal error. The finalize function in java for the VideoFrameRef class calls oniFrameRelease resulting in a fatal error when the garbage collector comes through, assuming it bothers to call the finalize function. To fix this I commented out a line as seen below.
JNIEnv g_env;
JNIEXPORT void JNICALL Java_org_openni_NativeMethods_oniFrameRelease
(JNIEnv *, jclass, jlong frame) {
//oniFrameRelease((OniFrame
)frame);
}

I also commented out oniFrameAddRef in java
private VideoFrameRef(long handle) {
//NativeMethods.oniFrameAddRef(handle);
mFrameHandle = handle;
}
but i'm not sure if that was necessary.

@blueeaglex
Copy link

Hi,I got the similar issue when I tried to use Openni2 on android.
#66
How are you getting on with this problem for now?

@BEIWG
Copy link

BEIWG commented Apr 18, 2018

Hi,I got the same issue when I tried to use Openni2(develop branch) on android 4.4
have you fixed it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants