Add safety checks when handling Android input

It is possible that input comes before the engine is fully initialized.
This fixes the crashes that ocurred when that happens.

(cherry picked from commit 995724b762)
This commit is contained in:
Ruslan Mustakov 2018-03-27 22:03:44 +07:00 committed by Hein-Pieter van Braam
parent d3ffc8ad0c
commit c8d0d38cab
1 changed files with 22 additions and 5 deletions

View File

@ -981,6 +981,9 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_newcontext(JNIEnv *en
} }
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_back(JNIEnv *env, jobject obj) { JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_back(JNIEnv *env, jobject obj) {
if (step == 0)
return;
os_android->main_loop_request_go_back(); os_android->main_loop_request_go_back();
} }
@ -1025,7 +1028,8 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, job
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch(JNIEnv *env, jobject obj, jint ev, jint pointer, jint count, jintArray positions) { JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch(JNIEnv *env, jobject obj, jint ev, jint pointer, jint count, jintArray positions) {
//__android_log_print(ANDROID_LOG_INFO,"godot","**TOUCH EVENT! - %p-%i\n",env,Thread::get_caller_id()); if (step == 0)
return;
Vector<OS_Android::TouchPos> points; Vector<OS_Android::TouchPos> points;
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
@ -1302,6 +1306,8 @@ static unsigned int android_get_keysym(unsigned int p_code) {
} }
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env, jobject obj, jint p_device, jint p_button, jboolean p_pressed) { JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env, jobject obj, jint p_device, jint p_button, jboolean p_pressed) {
if (step == 0)
return;
OS_Android::JoypadEvent jevent; OS_Android::JoypadEvent jevent;
jevent.device = p_device; jevent.device = p_device;
@ -1313,6 +1319,8 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env
} }
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv *env, jobject obj, jint p_device, jint p_axis, jfloat p_value) { JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv *env, jobject obj, jint p_device, jint p_axis, jfloat p_value) {
if (step == 0)
return;
OS_Android::JoypadEvent jevent; OS_Android::JoypadEvent jevent;
jevent.device = p_device; jevent.device = p_device;
@ -1324,6 +1332,9 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv *env,
} }
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv *env, jobject obj, jint p_device, jint p_hat_x, jint p_hat_y) { JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv *env, jobject obj, jint p_device, jint p_hat_x, jint p_hat_y) {
if (step == 0)
return;
OS_Android::JoypadEvent jevent; OS_Android::JoypadEvent jevent;
jevent.device = p_device; jevent.device = p_device;
jevent.type = OS_Android::JOY_EVENT_HAT; jevent.type = OS_Android::JOY_EVENT_HAT;
@ -1353,6 +1364,8 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyconnectionchanged(
} }
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jobject obj, jint p_scancode, jint p_unicode_char, jboolean p_pressed) { JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jobject obj, jint p_scancode, jint p_unicode_char, jboolean p_pressed) {
if (step == 0)
return;
Ref<InputEventKey> ievent; Ref<InputEventKey> ievent;
ievent.instance(); ievent.instance();
@ -1398,13 +1411,17 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gyroscope(JNIEnv *env
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusin(JNIEnv *env, jobject obj) { JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusin(JNIEnv *env, jobject obj) {
if (os_android && step > 0) if (step == 0)
return;
os_android->main_loop_focusin(); os_android->main_loop_focusin();
} }
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusout(JNIEnv *env, jobject obj) { JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusout(JNIEnv *env, jobject obj) {
if (os_android && step > 0) if (step == 0)
return;
os_android->main_loop_focusout(); os_android->main_loop_focusout();
} }