Game Development Reference
In-Depth Information
Fatal Errors
Fatal or unrecoverable errors occur in any type of software. In Doom, these errors are
cascaded back to Java where a message is presented to the user and then the application
aborts. The following fragment from jni_doom.h shows the callback name and signature for
this task:
#define CB_CLASS_FATAL_CB "OnFatalError"
#define CB_CLASS_FATAL_SIG "(Ljava/lang/String;)V"
This callback is simple (see Listing 5-18). It works as follows.
1.
It attaches to the current thread, aborting if no JNI environment is
available.
2.
It looks up the doom.jni.Natives Java class, aborting if not found.
3.
It looks up the doom.jni.Natives.OnFatalError(String) using the
method name and signature.
4.
It calls the static void method.
Listing 5-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);
 
Search WWH ::




Custom Search