I'm using the enum pattern to define a singleton in my application. I need to access methods of this singleton, but I can't seem to pass the singleton correctly.
I've tried passing the enum and creating a jobject as a globalRef out of it like this:
class FrameElapsedListener : public gkEngine::Listener{
public:
JNIEnv* env;
jobject entityManager;
FrameElapsedListener(JNIEnv* env, jobject entityManager) :
env(env),
entityManager(env->NewGlobalRef(entityManager)){}
~FrameElapsedListener(){
env->DeleteGlobalRef(entityManager);
}
void tick(gkScalar rate);
};
but I got a crash when using it that the "local ref" was out of scope like this:
jclass entityManagerClass = env->FindClass(entityManagerClassPath.c_str());
jmethodID entityManagerFrameElapsedMethodId = env->GetMethodID(entityManagerClass, "frameElapsed", "(F)V");
env->CallVoidMethod(entityManager, entityManagerFrameElapsedMethodId, rate); //crashes here
Now I'm trying to just get the singleton out of the enum, but I'm not sure how to grab enum values like that. Any advice?