Use a small function to release UIScreenMode after checking it is supported
authorKees Bakker <kees@ijzerbout.nl>
Tue, 18 Oct 2011 21:36:28 +0200
changeset 6019 3d8b1ada8ad5
parent 6018 fa4a3c1d857b
child 6020 5374ddd99862
Use a small function to release UIScreenMode after checking it is supported
src/video/uikit/SDL_uikitvideo.m
--- a/src/video/uikit/SDL_uikitvideo.m	Tue Oct 18 21:32:54 2011 +0200
+++ b/src/video/uikit/SDL_uikitvideo.m	Tue Oct 18 21:36:28 2011 +0200
@@ -242,6 +242,19 @@
     return 0;
 }
 
+static void
+UIKit_ReleaseUIScreenMode(SDL_DisplayMode * mode)
+{
+    if (!SDL_UIKit_supports_multiple_displays) {
+        // Not on at least iPhoneOS 3.2 (versions prior to iPad).
+        SDL_assert(mode->driverdata == NULL);
+    } else {
+        UIScreenMode *uimode = (UIScreenMode *) mode->driverdata;
+        [uimode release];
+        mode->driverdata = NULL;
+    }
+}
+
 void
 UIKit_VideoQuit(_THIS)
 {
@@ -252,14 +265,11 @@
         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;
+        UIKit_ReleaseUIScreenMode(&display->desktop_mode);
+        UIKit_ReleaseUIScreenMode(&display->current_mode);
         for (j = 0; j < display->num_display_modes; j++) {
             SDL_DisplayMode *mode = &display->display_modes[j];
-            [((UIScreenMode *) mode->driverdata) release];
-            mode->driverdata = NULL;
+            UIKit_ReleaseUIScreenMode(mode);
         }
     }
 }