Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid not running entire function?
    primarykey
    data
    text
    <p>I have no idea how to better frame this question. I am using JNI to do some image processing. I have three JNI calls, one to do initializations, one to do the image processing (so this one is called multiple times) and one to call all destroy/close methods.</p> <p>Now my problem is that I am somehow calling the image processing call AFTER destroy. I call destroy on the press of the back button. I am using camera preview so I call this destroy method in onSurfaceDestroyed. I put print statements to debug. These are the relevant code fragments - </p> <pre><code>public void destroy() { destroyTorch(torchState); torchState = 0; Log.d("ADebugTag", "torchstate in destroy = " + Long.toString(torchState)); } </code></pre> <p>This is the native function called by above - </p> <pre><code>JNIEXPORT void JNICALL Java_com_example_torchandroid_CameraClass_destroyTorch(JNIEnv *env, jobject thiz,jlong torchStateLocation) { __android_log_print(ANDROID_LOG_INFO, "Torchandroid", "Closing lua state"); lua_State *L = (lua_State*) torchStateLocation; lua_close(L); //Close lua state. } </code></pre> <p>And this is the native call that does the image processing. The following should not work after the above is called.</p> <pre><code>start = SystemClock.elapsedRealtime(); bProcessing = true; if(torchState != 0) { Log.d("ADebugTag", "Calling torch"); Log.d("ADebugTag", "torchstate = " + Long.toString(torchState)); callTorch(torchState, PreviewSizeWidth, PreviewSizeHeight, FrameData, pixels); } bitmap.setPixels(pixels, 0, PreviewSizeWidth, 0, 0, PreviewSizeWidth, PreviewSizeHeight); </code></pre> <p>The destroy method calls native which basically destroys any open states. There is a print statement in that native call stating that the call was successful. Now this is the order of the print statements - </p> <pre><code>Closing lua state //This is a print in native destroyTorch Calling torch torchstate = 462345328923482082342 //The pointer that was supposed to be set to 0 </code></pre> <p>Now the very fact that "Closing lua state" is output means that the following line, that is setting torchState to 0 should execute. However, it doesn't. I have no idea why this happens but this is causing a stack problem (obviously) because torchstate doesn't exist but gets used in the image processing call.</p> <p>What's more is that the line "torchstate in destroy" never prints which leads me to believe that part executes after the crash due to the memory leak. Is this because it is in different threads? Why is that? Is there any way to have them run in the same thread? They are, after all, not supposed to be running parallel.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload