How are static variables in C ++ code managed by JNI?

My question is, suppose I have a C ++ class with a singleton and through the JNI methods I call this singleton, every time I call from java in C ++ the singleton variable is changed because its static or it remains the same? and every time i call from java in c ++ does it run the method on a new thread or not?

Sample code:

in Java:

class NativeLib
{
  public native void updateFrame();
}

      

in C / C ++:

JNIEXPORT void JNICALL Java_com_Company_NativeLib_NativeLib_updateFrame()
{
   sceneManager::getInstance()->updateFrame();
}

      

Whether sceneManager :: getInstance () creates a new instance for each call, or the last instance created with its static variable.

My main problem is android of my application not displaying any logCat information why it crashed.

but if I comment out sceneManager :: getInstance () -> updateFrame (); it never crashes, so I think that ever Java makes a C ++ call, it is in a new thread which means static variables are not

+3


source to share


1 answer


Think of a virtual machine as a C / C ++ code library that your application accessed. Sometimes it gets rewritten into your code.

Singletons won't be recreated - it's just a method call. VM Dalvik threads are just pthreads, and any thread making its own call from Java code will be the thread that executes your C ++ code.



Your best bet is to include your own debugger. FWIW, one way to fail in logcat is to have built in recursion that overflows the stack. Another way is to change the signal handlers for SIGSEGV / SIGBUS and friends.

+1


source







All Articles