Make assert dialog work on Cocoa target even if we haven't initialized video.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 20 Apr 2011 15:14:18 -0400
changeset 55447bf3c86d8b60
parent 5543 82cd9b2ec39c
child 5545 978cc06ed5ad
Make assert dialog work on Cocoa target even if we haven't initialized video.
src/video/cocoa/SDL_cocoavideo.m
     1.1 --- a/src/video/cocoa/SDL_cocoavideo.m	Wed Apr 20 11:25:01 2011 +0200
     1.2 +++ b/src/video/cocoa/SDL_cocoavideo.m	Wed Apr 20 15:14:18 2011 -0400
     1.3 @@ -20,6 +20,7 @@
     1.4  */
     1.5  #include "SDL_config.h"
     1.6  
     1.7 +#include "SDL.h"
     1.8  #include "SDL_endian.h"
     1.9  #include "SDL_cocoavideo.h"
    1.10  #include "SDL_cocoashape.h"
    1.11 @@ -217,6 +218,14 @@
    1.12  SDL_assert_state
    1.13  SDL_PromptAssertion_cocoa(const SDL_assert_data *data)
    1.14  {
    1.15 +    const int initialized = (SDL_WasInit(SDL_INIT_VIDEO) != 0);
    1.16 +    if (!initialized) {
    1.17 +        if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) {
    1.18 +            fprintf(stderr, "Assertion failed AND couldn't init video mode!\n");
    1.19 +            return SDL_ASSERTION_BREAK;  /* oh well, crash hard. */
    1.20 +        }
    1.21 +    }
    1.22 +
    1.23      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    1.24  
    1.25      NSString *msg = [NSString stringWithFormat:
    1.26 @@ -242,6 +251,11 @@
    1.27      [alert addButtonWithTitle:@"Always Ignore"];
    1.28      const NSInteger clicked = [alert runModal];
    1.29      [pool release];
    1.30 +
    1.31 +    if (!initialized) {
    1.32 +        SDL_QuitSubSystem(SDL_INIT_VIDEO);
    1.33 +    }
    1.34 +
    1.35      return (SDL_assert_state) (clicked - NSAlertFirstButtonReturn);
    1.36  }
    1.37