Преглед на файлове

Android: prevent a dummy error message sending SDL_DISPLAYEVENT_ORIENTATION

In the usual case, first call to onNativeOrientationChanged() is done before
SDL has been initialised and would just set an error message
"Video subsystem has not been initialized" without sending the event.
Sylvain Becker преди 6 години
родител
ревизия
8dd915507e
променени са 2 файла, в които са добавени 6 реда и са изтрити 2 реда
  1. 1 0
      android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
  2. 5 2
      src/core/android/SDL_android.c

+ 1 - 0
android-project/app/src/main/java/org/libsdl/app/SDLActivity.java

@@ -260,6 +260,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
 
         // Get our current screen orientation and pass it down.
         mCurrentOrientation = SDLActivity.getCurrentOrientation();
+        // FIXME: with only one activity, SDL Thread is not yet started and this onNativeOrientationChanged() is ignored
         SDLActivity.onNativeOrientationChanged(mCurrentOrientation);
 
         setContentView(mLayout);

+ 5 - 2
src/core/android/SDL_android.c

@@ -583,8 +583,11 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeOrientationChanged)(
                                     JNIEnv *env, jclass jcls,
                                     jint orientation)
 {
-    SDL_VideoDisplay *display = SDL_GetDisplay(0);
-    SDL_SendDisplayEvent(display, SDL_DISPLAYEVENT_ORIENTATION, orientation);
+    SDL_VideoDevice *_this = SDL_GetVideoDevice();
+    if (_this) {
+        SDL_VideoDisplay *display = SDL_GetDisplay(0);
+        SDL_SendDisplayEvent(display, SDL_DISPLAYEVENT_ORIENTATION, orientation);
+    }
 }
 
 /* Paddown */