From 2bc1b2eb09cbf04d936e40329e40ae67a0eecb80 Mon Sep 17 00:00:00 2001 From: Shai Almog <67850168+shai-almog@users.noreply.github.com> Date: Fri, 17 Nov 2023 05:33:47 +0200 Subject: [PATCH] Fix for null pointer exception in safe area Fixed #3764 --- Ports/iOSPort/nativeSources/IOSNative.m | 28 ++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/Ports/iOSPort/nativeSources/IOSNative.m b/Ports/iOSPort/nativeSources/IOSNative.m index 727f783ef0..09761845f7 100644 --- a/Ports/iOSPort/nativeSources/IOSNative.m +++ b/Ports/iOSPort/nativeSources/IOSNative.m @@ -8286,37 +8286,41 @@ JAVA_BOOLEAN com_codename1_impl_ios_IOSNative_nativeIsAlphaMaskSupportedGlobal__ JAVA_INT com_codename1_impl_ios_IOSNative_getDisplaySafeInsetLeft___R_int(CN1_THREAD_STATE_MULTI_ARG JAVA_OBJECT instanceObject) { if (@available(iOS 11.0, *)) { UIWindow *window = UIApplication.sharedApplication.keyWindow; - return (JAVA_INT)(window.safeAreaInsets.left * scaleValue); - } else { - return 0; + if(window != nil && window.safeAreaInsets != nil) { + return (JAVA_INT)(window.safeAreaInsets.left * scaleValue); + } } + return 0; } JAVA_INT com_codename1_impl_ios_IOSNative_getDisplaySafeInsetTop___R_int(CN1_THREAD_STATE_MULTI_ARG JAVA_OBJECT instanceObject) { if (@available(iOS 11.0, *)) { UIWindow *window = UIApplication.sharedApplication.keyWindow; - return (JAVA_INT)(window.safeAreaInsets.top * scaleValue); - } else { - return 0; + if(window != nil && window.safeAreaInsets != nil) { + return (JAVA_INT)(window.safeAreaInsets.top * scaleValue); + } } + return 0; } JAVA_INT com_codename1_impl_ios_IOSNative_getDisplaySafeInsetRight___R_int(CN1_THREAD_STATE_MULTI_ARG JAVA_OBJECT instanceObject) { if (@available(iOS 11.0, *)) { UIWindow *window = UIApplication.sharedApplication.keyWindow; - return (JAVA_INT)(window.safeAreaInsets.right * scaleValue); - } else { - return 0; + if(window != nil && window.safeAreaInsets != nil) { + return (JAVA_INT)(window.safeAreaInsets.right * scaleValue); + } } + return 0; } JAVA_INT com_codename1_impl_ios_IOSNative_getDisplaySafeInsetBottom___R_int(CN1_THREAD_STATE_MULTI_ARG JAVA_OBJECT instanceObject) { if (@available(iOS 11.0, *)) { UIWindow *window = UIApplication.sharedApplication.keyWindow; - return (JAVA_INT)(window.safeAreaInsets.bottom * scaleValue); - } else { - return 0; + if(window != nil && window.safeAreaInsets != nil) { + return (JAVA_INT)(window.safeAreaInsets.bottom * scaleValue); + } } + return 0; } JAVA_INT com_codename1_impl_ios_IOSNative_getDisplayWidth___R_int(CN1_THREAD_STATE_MULTI_ARG JAVA_OBJECT instanceObject) {