Fixed bug #458 SDL-1.2
authorSam Lantinga
Tue, 24 Jul 2007 04:21:05 +0000
branchSDL-1.2
changeset 4090fedb379bedd0
parent 4089 37345dc3dd83
child 4091 98b219f9ff17
Fixed bug #458

------- Comment #7 From Christian Walther 2007-07-23 01:10:30 [reply] -------
Fix for some Cocoa memory management problems.

OK, I think I've nailed the memory management problems with the attached patch.
Too late for the release, but oh well. It shows that I haven't done much Cocoa
lately... took me a while to figure out that NSWindows don't retain their
delegate.
src/video/quartz/SDL_QuartzVideo.m
     1.1 --- a/src/video/quartz/SDL_QuartzVideo.m	Mon Jul 23 18:36:58 2007 +0000
     1.2 +++ b/src/video/quartz/SDL_QuartzVideo.m	Tue Jul 24 04:21:05 2007 +0000
     1.3 @@ -369,8 +369,8 @@
     1.4          
     1.5          /* If we still have a valid window, close it. */
     1.6          if ( qz_window ) {
     1.7 -            [ qz_window close ];
     1.8 -            [ qz_window release ];
     1.9 +            NSCAssert([ qz_window delegate ] == nil, @"full screen window shouldn't have a delegate"); /* if that should ever change, we'd have to release it here */
    1.10 +            [ qz_window close ]; /* includes release because [qz_window isReleasedWhenClosed] */
    1.11              qz_window = nil;
    1.12              window_view = nil;
    1.13          }
    1.14 @@ -398,9 +398,9 @@
    1.15      }
    1.16      /* Release window mode resources */
    1.17      else {
    1.18 -        
    1.19 -        [ qz_window close ];
    1.20 -        [ qz_window release ];
    1.21 +        id delegate = [ qz_window delegate ];
    1.22 +        [ qz_window close ]; /* includes release because [qz_window isReleasedWhenClosed] */
    1.23 +        if (delegate != nil) [ delegate release ];
    1.24          qz_window = nil;
    1.25          window_view = nil;
    1.26  
    1.27 @@ -747,7 +747,7 @@
    1.28              return NULL;
    1.29          }
    1.30      
    1.31 -        /*[ qz_window setReleasedWhenClosed:YES ];*/
    1.32 +        /*[ qz_window setReleasedWhenClosed:YES ];*/ /* no need to set this as it's the default for NSWindows */
    1.33          QZ_SetCaption(this, this->wm_title, this->wm_icon);
    1.34          [ qz_window setAcceptsMouseMovedEvents:YES ];
    1.35          [ qz_window setViewsNeedDisplay:NO ];
    1.36 @@ -755,7 +755,7 @@
    1.37              [ qz_window center ];
    1.38          }
    1.39          [ qz_window setDelegate:
    1.40 -            [ [ [ SDL_QuartzWindowDelegate alloc ] init ] autorelease ] ];
    1.41 +            [ [ SDL_QuartzWindowDelegate alloc ] init ] ];
    1.42          [ qz_window setContentView: [ [ [ SDL_QuartzView alloc ] init ] autorelease ] ];
    1.43      }
    1.44      /* We already have a window, just change its size */