Fixed bug 1303 - SDL_CreateFromWindow duplicates window (Cocoa only)
authorSam Lantinga <slouken@libsdl.org>
Sun, 08 Jan 2012 00:39:41 -0500
changeset 6185b91e7565e877
parent 6184 976d9ec6c290
child 6186 e565ac981de6
Fixed bug 1303 - SDL_CreateFromWindow duplicates window (Cocoa only)

Jens Köhler 2011-09-09 04:47:40 PDT

When calling SDL_CreateWindowFrom with a NSWindow which already contains a
NSView, the window will be duplicated because another NSView is added. I
attached a possible fix that prevents the creation of a second NSView.
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Sun Jan 08 00:36:32 2012 -0500
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Sun Jan 08 00:39:41 2012 -0500
     1.3 @@ -526,9 +526,13 @@
     1.4      /* Fill in the SDL window with the window data */
     1.5      {
     1.6          NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
     1.7 -        NSView *contentView = [[SDLView alloc] initWithFrame:rect];
     1.8 -        [nswindow setContentView: contentView];
     1.9 -        [contentView release];
    1.10 +        NSView *contentView = [ nswindow contentView ];
    1.11 +        /* Create view if not already exists */
    1.12 +        if (!contentView) {
    1.13 +            contentView = [[SDLView alloc] initWithFrame:rect];
    1.14 +            [nswindow setContentView: contentView];
    1.15 +            [contentView release];
    1.16 +        }
    1.17  
    1.18          ConvertNSRect(&rect);
    1.19          window->x = (int)rect.origin.x;