Game Development Reference
In-Depth Information
It looks up the
doom.jni.Natives
Java class, aborting if not found.
•
It looks up the
doom.jni.Natives.OnFatalError(String)
using the method name
and signature.
•
•
It calls the static void method.
Listing 7-18.
Cascading Fatal Errors
/**
* Called when a fatal error has occurred.
* The receiver should terminate
*/
void jni_fatal_error(const char * text) {
JNIEnv *env;
if ( !g_VM) {
printf("JNI FATAL: No JNI Environment available. %s\n", text);
exit(-1);
}
(*g_VM)->AttachCurrentThread (g_VM, (void **) &env, NULL);
if ( !env) {
printf("JNI FATAL: Unable to attach to thread: %s.\n", text);
exit(-1);
}
if ( !jNativesCls ) {
jNativesCls = (*env)->FindClass(env, CB_CLASS);
if ( jNativesCls == 0 ) {
printf("JNI FATAL: Unable to find class: %s", CB_CLASS);
exit(-1);
}
}
jmethodID mid = (*env)->GetStaticMethodID(env, jNativesCls
, CB_CLASS_FATAL_CB
, CB_CLASS_FATAL_SIG);
if (mid) {
(*env)->CallStaticVoidMethod(env, jNativesCls
, mid
, (*env)->NewStringUTF(env, text) );
}
else {
printf("JNI FATAL: Unable to find method: %s, signature: %s\n"
, CB_CLASS_MSG_CB, CB_CLASS_MSG_SIG );
exit (-1);
}
}