Browse Source

Add failsafe for `love.window.getSafeArea` in Android.

In case it uses older Java files, the function can safely be called without
causing Java crash.

--HG--
branch : android-safearea
Miku AuahDark 6 years ago
parent
commit
b3497f42e4
1 changed files with 4 additions and 1 deletions
  1. 4 1
      src/common/android.cpp

+ 4 - 1
src/common/android.cpp

@@ -98,7 +98,10 @@ bool getSafeArea(int &top, int &left, int &bottom, int &right)
 	jmethodID methodID = env->GetMethodID(clazz, "initializeSafeArea", "()Z");
 	bool hasSafeArea = false;
 
-	if ((hasSafeArea = env->CallBooleanMethod(activity, methodID)))
+	if (methodID == nullptr)
+		// NoSuchMethodException is thrown in case methodID is null
+		env->ExceptionClear();
+	else if ((hasSafeArea = env->CallBooleanMethod(activity, methodID)))
 	{
 		top = env->GetIntField(activity, env->GetFieldID(clazz, "safeAreaTop", "I"));
 		left = env->GetIntField(activity, env->GetFieldID(clazz, "safeAreaLeft", "I"));