|
@@ -112,6 +112,40 @@ static void _initialize_java_modules() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+static void _terminate(JNIEnv *env, bool p_restart = false) {
|
|
|
+ step.set(-1); // Ensure no further steps are attempted and no further events are sent
|
|
|
+
|
|
|
+ // lets cleanup
|
|
|
+ if (java_class_wrapper) {
|
|
|
+ memdelete(java_class_wrapper);
|
|
|
+ }
|
|
|
+ if (input_handler) {
|
|
|
+ delete input_handler;
|
|
|
+ }
|
|
|
+ // Whether restarting is handled by 'Main::cleanup()'
|
|
|
+ bool restart_on_cleanup = false;
|
|
|
+ if (os_android) {
|
|
|
+ restart_on_cleanup = os_android->is_restart_on_exit_set();
|
|
|
+ os_android->main_loop_end();
|
|
|
+ Main::cleanup();
|
|
|
+ delete os_android;
|
|
|
+ }
|
|
|
+ if (godot_io_java) {
|
|
|
+ delete godot_io_java;
|
|
|
+ }
|
|
|
+ if (godot_java) {
|
|
|
+ godot_java->destroy_offscreen_gl(env);
|
|
|
+ if (!restart_on_cleanup) {
|
|
|
+ if (p_restart) {
|
|
|
+ godot_java->restart(env);
|
|
|
+ } else {
|
|
|
+ godot_java->force_quit(env);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ delete godot_java;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
extern "C" {
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setVirtualKeyboardHeight(JNIEnv *env, jclass clazz, jint p_height) {
|
|
@@ -145,24 +179,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv *en
|
|
|
}
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_ondestroy(JNIEnv *env, jclass clazz) {
|
|
|
- // lets cleanup
|
|
|
- if (java_class_wrapper) {
|
|
|
- memdelete(java_class_wrapper);
|
|
|
- }
|
|
|
- if (godot_io_java) {
|
|
|
- delete godot_io_java;
|
|
|
- }
|
|
|
- if (godot_java) {
|
|
|
- godot_java->destroy_offscreen_gl(env);
|
|
|
- delete godot_java;
|
|
|
- }
|
|
|
- if (input_handler) {
|
|
|
- delete input_handler;
|
|
|
- }
|
|
|
- if (os_android) {
|
|
|
- os_android->main_loop_end();
|
|
|
- delete os_android;
|
|
|
- }
|
|
|
+ _terminate(env, false);
|
|
|
}
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL Java_org_godotengine_godot_GodotLib_setup(JNIEnv *env, jclass clazz, jobjectArray p_cmdline) {
|
|
@@ -225,9 +242,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_newcontext(JNIEnv *en
|
|
|
os_android->set_offscreen_gl_available(godot_java->create_offscreen_gl(env));
|
|
|
} else {
|
|
|
// GL context recreated because it was lost; restart app to let it reload everything
|
|
|
- step.set(-1); // Ensure no further steps are attempted and no further events are sent
|
|
|
- os_android->main_loop_end();
|
|
|
- godot_java->restart(env);
|
|
|
+ _terminate(env, true);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -276,7 +291,7 @@ JNIEXPORT jboolean JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env,
|
|
|
|
|
|
bool should_swap_buffers = false;
|
|
|
if (os_android->main_loop_iterate(&should_swap_buffers)) {
|
|
|
- godot_java->force_quit(env);
|
|
|
+ _terminate(env, false);
|
|
|
}
|
|
|
|
|
|
return should_swap_buffers;
|