Fix up some retain/release issues with UIScreenMode objects.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 14 Oct 2011 20:47:53 -0400
changeset 5997 69875bbf83d8
parent 5996 102a9ec1ea13
child 5998 e9b9ef14aef4
Fix up some retain/release issues with UIScreenMode objects. Fixes Bugzilla #1191. This patch is based on work done by Vittorio Giovara.
src/video/uikit/SDL_uikitvideo.m
src/video/uikit/SDL_uikitwindow.m
--- a/src/video/uikit/SDL_uikitvideo.m	Sat Oct 15 23:50:06 2011 -0700
+++ b/src/video/uikit/SDL_uikitvideo.m	Fri Oct 14 20:47:53 2011 -0400
@@ -212,7 +212,8 @@
     mode.h = h;
     mode.refresh_rate = 0;
     
-    [uimode retain];
+    [uimode retain];  // once for the desktop_mode
+    [uimode retain];  // once for the current_mode
     mode.driverdata = uimode;
 
     SDL_zero(display);
@@ -286,13 +287,14 @@
         UIScreen *uiscreen = (UIScreen *) display->driverdata;
         [uiscreen release];
         display->driverdata = NULL;
+        [((UIScreenMode *) display->desktop_mode.driverdata) release];
+        display->desktop_mode.driverdata = NULL;
+        [((UIScreenMode *) display->current_mode.driverdata) release];
+        display->current_mode.driverdata = NULL;
         for (j = 0; j < display->num_display_modes; j++) {
             SDL_DisplayMode *mode = &display->display_modes[j];
-            UIScreenMode *uimode = (UIScreenMode *) mode->driverdata;
-            if (uimode) {
-                [uimode release];
-                mode->driverdata = NULL;
-            }
+            [((UIScreenMode *) mode->driverdata) release];
+            mode->driverdata = NULL;
         }
     }
 }
--- a/src/video/uikit/SDL_uikitwindow.m	Sat Oct 15 23:50:06 2011 -0700
+++ b/src/video/uikit/SDL_uikitwindow.m	Fri Oct 14 20:47:53 2011 -0400
@@ -151,8 +151,13 @@
             if (bestmode) {
                 UIScreenMode *uimode = (UIScreenMode *) bestmode->driverdata;
                 [uiscreen setCurrentMode:uimode];
-                display->desktop_mode = *bestmode;
+
+                // desktop_mode doesn't change here (the higher level will
+                //  use it to set all the screens back to their defaults
+                //  upon window destruction, SDL_Quit(), etc.
+                [((UIScreenMode *) display->current_mode.driverdata) release];
                 display->current_mode = *bestmode;
+                [((UIScreenMode *) display->current_mode.driverdata) retain];
             }
         }
     }