Fix up some retain/release issues with UIScreenMode objects.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 14 Oct 2011 20:47:53 -0400
changeset 599769875bbf83d8
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
     1.1 --- a/src/video/uikit/SDL_uikitvideo.m	Sat Oct 15 23:50:06 2011 -0700
     1.2 +++ b/src/video/uikit/SDL_uikitvideo.m	Fri Oct 14 20:47:53 2011 -0400
     1.3 @@ -212,7 +212,8 @@
     1.4      mode.h = h;
     1.5      mode.refresh_rate = 0;
     1.6      
     1.7 -    [uimode retain];
     1.8 +    [uimode retain];  // once for the desktop_mode
     1.9 +    [uimode retain];  // once for the current_mode
    1.10      mode.driverdata = uimode;
    1.11  
    1.12      SDL_zero(display);
    1.13 @@ -286,13 +287,14 @@
    1.14          UIScreen *uiscreen = (UIScreen *) display->driverdata;
    1.15          [uiscreen release];
    1.16          display->driverdata = NULL;
    1.17 +        [((UIScreenMode *) display->desktop_mode.driverdata) release];
    1.18 +        display->desktop_mode.driverdata = NULL;
    1.19 +        [((UIScreenMode *) display->current_mode.driverdata) release];
    1.20 +        display->current_mode.driverdata = NULL;
    1.21          for (j = 0; j < display->num_display_modes; j++) {
    1.22              SDL_DisplayMode *mode = &display->display_modes[j];
    1.23 -            UIScreenMode *uimode = (UIScreenMode *) mode->driverdata;
    1.24 -            if (uimode) {
    1.25 -                [uimode release];
    1.26 -                mode->driverdata = NULL;
    1.27 -            }
    1.28 +            [((UIScreenMode *) mode->driverdata) release];
    1.29 +            mode->driverdata = NULL;
    1.30          }
    1.31      }
    1.32  }
     2.1 --- a/src/video/uikit/SDL_uikitwindow.m	Sat Oct 15 23:50:06 2011 -0700
     2.2 +++ b/src/video/uikit/SDL_uikitwindow.m	Fri Oct 14 20:47:53 2011 -0400
     2.3 @@ -151,8 +151,13 @@
     2.4              if (bestmode) {
     2.5                  UIScreenMode *uimode = (UIScreenMode *) bestmode->driverdata;
     2.6                  [uiscreen setCurrentMode:uimode];
     2.7 -                display->desktop_mode = *bestmode;
     2.8 +
     2.9 +                // desktop_mode doesn't change here (the higher level will
    2.10 +                //  use it to set all the screens back to their defaults
    2.11 +                //  upon window destruction, SDL_Quit(), etc.
    2.12 +                [((UIScreenMode *) display->current_mode.driverdata) release];
    2.13                  display->current_mode = *bestmode;
    2.14 +                [((UIScreenMode *) display->current_mode.driverdata) retain];
    2.15              }
    2.16          }
    2.17      }