Details
-
Bug
-
Resolution: Incomplete
-
P3: Somewhat important
-
None
-
5.9.0
Description
Found this random crash when app is thrown out of the recent apps list or when using Android Developer options => "Don't keep Activities" and hitting Home button. The app is killed with "JNI DETECTED ERROR IN APPLICATION ... use of deleted global ref 0x....".
The point of the crash:
androidjnimain.cpp:
void destroySurface(int surfaceId) .... env->CallStaticVoidMethod(m_applicationClass, m_destroySurfaceMethodID, surfaceId);
Turns out that this may be somehow executed after terminateQt when m_applicationClass is already deleted.
A rude hotfix is:
In terminateQt():
... env->DeleteGlobalRef(m_applicationClass); m_applicationClass = nullptr; // Add this line ...
In destroySurface:
QJNIEnvironmentPrivate env; if (env && m_applicationClass) // Add check for m_applicationClass here env->CallStaticVoidMethod(m_applicationClass, m_destroySurfaceMethodID, surfaceId);
However, it is probably not the best way to fix.
IMO the best idea is to remove call for terminateQt from Java and call it in a global scope guard so the JNI references will stay alive until static deinitialization of the libraries.