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
This commit is contained in:
Miku AuahDark
2019-02-09 18:55:48 +08:00
parent 4a08c0f7c1
commit b3497f42e4
+4 -1
View File
@@ -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"));