Commit 723f5cea430d84da5a88e148c431f9e04e4e60c6

Sylvain 2021-10-12T20:58:58

Fixed bug #4825 - NullPointerException on SDLActivity.getCurrentOrientation() (Thanks Benau!)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
index 2d83b9f..d71363f 100644
--- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
+++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
@@ -379,11 +379,13 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
     }
 
     public static int getCurrentOrientation() {
-        final Context context = SDLActivity.getContext();
-        final Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
-
         int result = SDL_ORIENTATION_UNKNOWN;
 
+        if (mSingleton == null) {
+            return result;
+        }
+        Display display = SDLActivity.mSingleton.getWindowManager().getDefaultDisplay();
+
         switch (display.getRotation()) {
             case Surface.ROTATION_0:
                 result = SDL_ORIENTATION_PORTRAIT;