iOS: Also do the Dictation crash workaround before executing the animation callback.
authorAlex Szpakowski <slime73@gmail.com>
Sat, 02 Apr 2016 13:21:01 -0300
changeset 10141fe9cf7c678f4
parent 10140 6dd5f49e4a77
child 10142 bc8ac6c0cd98
iOS: Also do the Dictation crash workaround before executing the animation callback.
src/video/uikit/SDL_uikitevents.m
src/video/uikit/SDL_uikitopengles.h
src/video/uikit/SDL_uikitopengles.m
src/video/uikit/SDL_uikitviewcontroller.m
     1.1 --- a/src/video/uikit/SDL_uikitevents.m	Sat Apr 02 11:54:05 2016 -0300
     1.2 +++ b/src/video/uikit/SDL_uikitevents.m	Sat Apr 02 13:21:01 2016 -0300
     1.3 @@ -26,6 +26,7 @@
     1.4  
     1.5  #include "SDL_uikitvideo.h"
     1.6  #include "SDL_uikitevents.h"
     1.7 +#include "SDL_uikitopengles.h"
     1.8  
     1.9  #import <Foundation/Foundation.h>
    1.10  
    1.11 @@ -63,19 +64,8 @@
    1.12          result = CFRunLoopRunInMode((CFStringRef)UITrackingRunLoopMode, seconds, TRUE);
    1.13      } while(result == kCFRunLoopRunHandledSource);
    1.14  
    1.15 -    @autoreleasepool {
    1.16 -        /* Some iOS system functionality (such as Dictation on the on-screen
    1.17 -           keyboard) uses its own OpenGL ES context but doesn't restore the
    1.18 -           previous one when it's done. This is a workaround to make sure the
    1.19 -           expected SDL-created OpenGL ES context is active after the OS is
    1.20 -           finished running its own code for the frame. If this isn't done, the
    1.21 -           app may crash or have other nasty symptoms when Dictation is used.
    1.22 -         */
    1.23 -        EAGLContext *context = (__bridge EAGLContext *) SDL_GL_GetCurrentContext();
    1.24 -        if (context != NULL && [EAGLContext currentContext] != context) {
    1.25 -            [EAGLContext setCurrentContext:context];
    1.26 -        }
    1.27 -    }
    1.28 +    /* See the comment in the function definition. */
    1.29 +    UIKit_GL_RestoreCurrentContext();
    1.30  }
    1.31  
    1.32  #endif /* SDL_VIDEO_DRIVER_UIKIT */
     2.1 --- a/src/video/uikit/SDL_uikitopengles.h	Sat Apr 02 11:54:05 2016 -0300
     2.2 +++ b/src/video/uikit/SDL_uikitopengles.h	Sat Apr 02 13:21:01 2016 -0300
     2.3 @@ -33,6 +33,8 @@
     2.4  extern void *UIKit_GL_GetProcAddress(_THIS, const char *proc);
     2.5  extern int UIKit_GL_LoadLibrary(_THIS, const char *path);
     2.6  
     2.7 +extern void UIKit_GL_RestoreCurrentContext();
     2.8 +
     2.9  #endif
    2.10  
    2.11  /* vi: set ts=4 sw=4 expandtab: */
     3.1 --- a/src/video/uikit/SDL_uikitopengles.m	Sat Apr 02 11:54:05 2016 -0300
     3.2 +++ b/src/video/uikit/SDL_uikitopengles.m	Sat Apr 02 13:21:01 2016 -0300
     3.3 @@ -217,6 +217,24 @@
     3.4      }
     3.5  }
     3.6  
     3.7 +void
     3.8 +UIKit_GL_RestoreCurrentContext()
     3.9 +{
    3.10 +    @autoreleasepool {
    3.11 +        /* Some iOS system functionality (such as Dictation on the on-screen
    3.12 +         keyboard) uses its own OpenGL ES context but doesn't restore the
    3.13 +         previous one when it's done. This is a workaround to make sure the
    3.14 +         expected SDL-created OpenGL ES context is active after the OS is
    3.15 +         finished running its own code for the frame. If this isn't done, the
    3.16 +         app may crash or have other nasty symptoms when Dictation is used.
    3.17 +         */
    3.18 +        EAGLContext *context = (__bridge EAGLContext *) SDL_GL_GetCurrentContext();
    3.19 +        if (context != NULL && [EAGLContext currentContext] != context) {
    3.20 +            [EAGLContext setCurrentContext:context];
    3.21 +        }
    3.22 +    }
    3.23 +}
    3.24 +
    3.25  #endif /* SDL_VIDEO_DRIVER_UIKIT */
    3.26  
    3.27  /* vi: set ts=4 sw=4 expandtab: */
     4.1 --- a/src/video/uikit/SDL_uikitviewcontroller.m	Sat Apr 02 11:54:05 2016 -0300
     4.2 +++ b/src/video/uikit/SDL_uikitviewcontroller.m	Sat Apr 02 13:21:01 2016 -0300
     4.3 @@ -33,6 +33,7 @@
     4.4  #include "SDL_uikitvideo.h"
     4.5  #include "SDL_uikitmodes.h"
     4.6  #include "SDL_uikitwindow.h"
     4.7 +#include "SDL_uikitopengles.h"
     4.8  
     4.9  #if SDL_IPHONE_KEYBOARD
    4.10  #include "keyinfotable.h"
    4.11 @@ -102,6 +103,9 @@
    4.12  {
    4.13      /* Don't run the game loop while a messagebox is up */
    4.14      if (!UIKit_ShowingMessageBox()) {
    4.15 +        /* See the comment in the function definition. */
    4.16 +        UIKit_GL_RestoreCurrentContext();
    4.17 +
    4.18          animationCallback(animationCallbackParam);
    4.19      }
    4.20  }