src/video/android/SDL_androidwindow.c
changeset 12496 93771c30420b
parent 12495 219a154f54cb
child 12497 9e13f3286831
     1.1 --- a/src/video/android/SDL_androidwindow.c	Thu Jan 03 13:38:33 2019 +0100
     1.2 +++ b/src/video/android/SDL_androidwindow.c	Thu Jan 03 14:18:06 2019 +0100
     1.3 @@ -41,12 +41,14 @@
     1.4  {
     1.5      SDL_WindowData *data;
     1.6      int retval = 0;
     1.7 -    
     1.8 +
     1.9 +    SDL_SemWait(Android_ActivitySem);
    1.10 +
    1.11      if (Android_Window) {
    1.12          retval = SDL_SetError("Android only supports one window");
    1.13          goto endfunction;
    1.14      }
    1.15 -    
    1.16 +
    1.17      Android_PauseSem = SDL_CreateSemaphore(0);
    1.18      Android_ResumeSem = SDL_CreateSemaphore(0);
    1.19  
    1.20 @@ -67,15 +69,15 @@
    1.21      /* One window, it always has focus */
    1.22      SDL_SetMouseFocus(window);
    1.23      SDL_SetKeyboardFocus(window);
    1.24 -    
    1.25 +
    1.26      data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
    1.27      if (!data) {
    1.28          retval = SDL_OutOfMemory();
    1.29          goto endfunction;
    1.30      }
    1.31 -    
    1.32 +
    1.33      data->native_window = Android_JNI_GetNativeWindow();
    1.34 -    
    1.35 +
    1.36      if (!data->native_window) {
    1.37          SDL_free(data);
    1.38          retval = SDL_SetError("Could not fetch native window");
    1.39 @@ -99,7 +101,9 @@
    1.40      Android_Window = window;
    1.41  
    1.42  endfunction:
    1.43 -    
    1.44 +
    1.45 +    SDL_SemPost(Android_ActivitySem);
    1.46 +
    1.47      return retval;
    1.48  }
    1.49  
    1.50 @@ -146,14 +150,16 @@
    1.51  
    1.52  void
    1.53  Android_DestroyWindow(_THIS, SDL_Window *window)
    1.54 -{ 
    1.55 +{
    1.56 +    SDL_SemWait(Android_ActivitySem);
    1.57 +
    1.58      if (window == Android_Window) {
    1.59          Android_Window = NULL;
    1.60          if (Android_PauseSem) SDL_DestroySemaphore(Android_PauseSem);
    1.61          if (Android_ResumeSem) SDL_DestroySemaphore(Android_ResumeSem);
    1.62          Android_PauseSem = NULL;
    1.63          Android_ResumeSem = NULL;
    1.64 -        
    1.65 +
    1.66          if (window->driverdata) {
    1.67              SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    1.68              if (data->egl_surface != EGL_NO_SURFACE) {
    1.69 @@ -166,6 +172,8 @@
    1.70              window->driverdata = NULL;
    1.71          }
    1.72      }
    1.73 +
    1.74 +    SDL_SemPost(Android_ActivitySem);
    1.75  }
    1.76  
    1.77  SDL_bool