Merged default into iOS-improvements iOS-improvements
authorAlex Szpakowski <slime73@gmail.com>
Wed, 06 Aug 2014 13:50:50 -0300
branchiOS-improvements
changeset 9512 c9f61d1dac7b
parent 9511 f08e88fe9de5 (current diff)
parent 9045 c689ac0e8411 (diff)
child 9513 34d9391e7d3e
Merged default into iOS-improvements
src/video/uikit/SDL_uikitopengles.m
--- a/src/video/uikit/SDL_uikitopengles.m	Wed Aug 06 03:32:59 2014 -0300
+++ b/src/video/uikit/SDL_uikitopengles.m	Wed Aug 06 13:50:50 2014 -0300
@@ -53,15 +53,8 @@
 UIKit_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
 {
     @autoreleasepool {
-        if (context) {
-            SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
-            [data.view setCurrentContext];
-        }
-        else {
-            [EAGLContext setCurrentContext: nil];
-        }
+        [EAGLContext setCurrentContext:(__bridge EAGLContext *)context];
     }
-
     return 0;
 }
 
@@ -169,8 +162,9 @@
             uiwindow.rootViewController = view.viewcontroller;
         }
 
-        if (UIKit_GL_MakeCurrent(_this, window, (__bridge SDL_GLContext)(view)) < 0) {
-            UIKit_GL_DeleteContext(_this, (SDL_GLContext) CFBridgingRetain(view));
+        EAGLContext *context = view.context;
+        if (UIKit_GL_MakeCurrent(_this, window, (__bridge SDL_GLContext) context) < 0) {
+            UIKit_GL_DeleteContext(_this, (SDL_GLContext) CFBridgingRetain(context));
             return NULL;
         }
 
@@ -180,7 +174,7 @@
             SDL_SetKeyboardFocus(window);
         }
 
-        return (SDL_GLContext) CFBridgingRetain(view);
+        return (SDL_GLContext) CFBridgingRetain(context);
     }
 }
 
@@ -188,16 +182,29 @@
 UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
 {
     @autoreleasepool {
-        /* the delegate has retained the view, this will release him */
-        SDL_uikitopenglview *view = (SDL_uikitopenglview *)CFBridgingRelease(context);
-        if (view.viewcontroller) {
-            UIWindow *uiwindow = (UIWindow *)view.superview;
-            if (uiwindow.rootViewController == view.viewcontroller) {
-                uiwindow.rootViewController = nil;
+        SDL_Window *window;
+        EAGLContext *eaglcontext = (EAGLContext *) CFBridgingRelease(context);
+
+        /* Find the view associated with this context */
+        for (window = _this->windows; window; window = window->next) {
+            SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
+            SDL_uikitopenglview *view = data.view;
+            if (view.context == eaglcontext) {
+                /* the delegate has retained the view, this will release him */
+                if (view.viewcontroller) {
+                    UIWindow *uiwindow = (UIWindow *)view.superview;
+                    if (uiwindow.rootViewController == view.viewcontroller) {
+                        uiwindow.rootViewController = nil;
+                    }
+                    view.viewcontroller.view = nil;
+                    view.viewcontroller = nil;
+                }
+                [view removeFromSuperview];
+
+                data.view = nil;
+                return;
             }
-            view.viewcontroller.view = nil;
         }
-        [view removeFromSuperview];
     }
 }