From a8e1bd63036b6b419087309d5b50acea87c7b5f0 Mon Sep 17 00:00:00 2001 From: Shai Almog <67850168+shai-almog@users.noreply.github.com> Date: Tue, 21 Nov 2023 11:11:10 +0200 Subject: [PATCH] Another workaround for NPE in safe area on iOS Fixed #3764 again. I'm guessing this is caused because of a threading issue in which case the issue can be ignored and refreshed later on. So the NPE is swallowed. --- .../com/codename1/impl/ios/IOSImplementation.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Ports/iOSPort/src/com/codename1/impl/ios/IOSImplementation.java b/Ports/iOSPort/src/com/codename1/impl/ios/IOSImplementation.java index 010140ed18..e9e504a9af 100644 --- a/Ports/iOSPort/src/com/codename1/impl/ios/IOSImplementation.java +++ b/Ports/iOSPort/src/com/codename1/impl/ios/IOSImplementation.java @@ -253,11 +253,15 @@ public Rectangle getDisplaySafeArea(Rectangle rect) { if (rect == null) { rect = new Rectangle(); } - int x = nativeInstance.getDisplaySafeInsetLeft(); - int y = nativeInstance.getDisplaySafeInsetTop(); - int w = getDisplayWidth() - nativeInstance.getDisplaySafeInsetRight() - x; - int h = getDisplayHeight() - nativeInstance.getDisplaySafeInsetBottom() - y; - rect.setBounds(x, y, w, h); + try { + int x = nativeInstance.getDisplaySafeInsetLeft(); + int y = nativeInstance.getDisplaySafeInsetTop(); + int w = getDisplayWidth() - nativeInstance.getDisplaySafeInsetRight() - x; + int h = getDisplayHeight() - nativeInstance.getDisplaySafeInsetBottom() - y; + rect.setBounds(x, y, w, h); + } catch (NullPointerException err) { + Log.p("Invalid bounds in getDisplaySafeArea, if this message repeats frequently please let us know..."); + } return rect; }