Android: prevent a dummy error message sending SDL_DISPLAYEVENT_ORIENTATION
authorSylvain Becker <sylvain.becker@gmail.com>
Wed, 09 Jan 2019 23:19:26 +0100
changeset 125155cd74fbb01d7
parent 12514 8034efde00c5
child 12516 d1d64b025981
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.
android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
src/core/android/SDL_android.c
     1.1 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Wed Jan 09 22:49:49 2019 +0100
     1.2 +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Wed Jan 09 23:19:26 2019 +0100
     1.3 @@ -260,6 +260,7 @@
     1.4  
     1.5          // Get our current screen orientation and pass it down.
     1.6          mCurrentOrientation = SDLActivity.getCurrentOrientation();
     1.7 +        // FIXME: with only one activity, SDL Thread is not yet started and this onNativeOrientationChanged() is ignored
     1.8          SDLActivity.onNativeOrientationChanged(mCurrentOrientation);
     1.9  
    1.10          setContentView(mLayout);
     2.1 --- a/src/core/android/SDL_android.c	Wed Jan 09 22:49:49 2019 +0100
     2.2 +++ b/src/core/android/SDL_android.c	Wed Jan 09 23:19:26 2019 +0100
     2.3 @@ -583,8 +583,11 @@
     2.4                                      JNIEnv *env, jclass jcls,
     2.5                                      jint orientation)
     2.6  {
     2.7 -    SDL_VideoDisplay *display = SDL_GetDisplay(0);
     2.8 -    SDL_SendDisplayEvent(display, SDL_DISPLAYEVENT_ORIENTATION, orientation);
     2.9 +    SDL_VideoDevice *_this = SDL_GetVideoDevice();
    2.10 +    if (_this) {
    2.11 +        SDL_VideoDisplay *display = SDL_GetDisplay(0);
    2.12 +        SDL_SendDisplayEvent(display, SDL_DISPLAYEVENT_ORIENTATION, orientation);
    2.13 +    }
    2.14  }
    2.15  
    2.16  /* Paddown */