I need to work with assets in my resource folder from C / C ++ code. Is it safe to cache a pointer to AAssetManager like this ...:
AAssetManager* assetMgr = NULL; void Java_com_example_createAssetManager(JNIEnv* env, jclass clazz, jobject assetManager) { AAssetManager* mgr = AAssetManager_fromJava(env, assetManager); assert(NULL != mgr); assetMgr = mgr; }
... and then use it whenever I need it? CreateAssetManager is called from the Java method onCreate of the main activity (UI thread), but the use in C / C ++ is that when processing the nativly rendering and tick of the game from its own methods in the GLSurfaceView implementation.
1) does assetMgr pointer point to a valid durin object for the entire application? Is it enough to create it just like a static variable on the Java side (in the Activity class), so the garbage collector will not destroy it?
2) is there any danger, will I encounter some problems with threads?
Thanks Tom Atom
source share