Remove the viewcontroller from the window when he OpenGL context is destroyed
authorSam Lantinga <slouken@libsdl.org>
Sun, 30 Sep 2012 01:01:48 -0700
changeset 6521 f36bbe0a10c9
parent 6520 7a7726af31c1
child 6522 edacce9402fb
Remove the viewcontroller from the window when he OpenGL context is destroyed
src/video/uikit/SDL_uikitopengles.m
--- a/src/video/uikit/SDL_uikitopengles.m	Sat Sep 29 18:52:00 2012 -0700
+++ b/src/video/uikit/SDL_uikitopengles.m	Sun Sep 30 01:01:48 2012 -0700
@@ -132,15 +132,14 @@
         [view->viewcontroller setView:view];
         [view->viewcontroller retain];
     }
+    [uiwindow addSubview: view];
     
     // The view controller needs to be the root in order to control rotation on iOS 6.0
     if (uiwindow.rootViewController == nil) {
         uiwindow.rootViewController = view->viewcontroller;
-    } else {
-        [uiwindow addSubview: view];
     }
 
-    if ( UIKit_GL_MakeCurrent(_this, window, view) < 0 ) {
+    if (UIKit_GL_MakeCurrent(_this, window, view) < 0) {
         UIKit_GL_DeleteContext(_this, view);
         return NULL;
     }
@@ -159,6 +158,10 @@
     /* the delegate has retained the view, this will release him */
     SDL_uikitopenglview *view = (SDL_uikitopenglview *)context;
     if (view->viewcontroller) {
+        UIWindow *uiwindow = (UIWindow *)view.superview;
+        if (uiwindow.rootViewController == view->viewcontroller) {
+            uiwindow.rootViewController = nil;
+        }
         [view->viewcontroller setView:nil];
         [view->viewcontroller release];
     }