From 19396a898f0042bef5cf1786fc16ce12bfae52f8 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 20 Apr 2011 15:14:18 -0400 Subject: [PATCH] Make assert dialog work on Cocoa target even if we haven't initialized video. --- src/video/cocoa/SDL_cocoavideo.m | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m index a8f1d2104..c31b25b33 100644 --- a/src/video/cocoa/SDL_cocoavideo.m +++ b/src/video/cocoa/SDL_cocoavideo.m @@ -20,6 +20,7 @@ */ #include "SDL_config.h" +#include "SDL.h" #include "SDL_endian.h" #include "SDL_cocoavideo.h" #include "SDL_cocoashape.h" @@ -217,6 +218,14 @@ SDL_assert_state SDL_PromptAssertion_cocoa(const SDL_assert_data *data) { + const int initialized = (SDL_WasInit(SDL_INIT_VIDEO) != 0); + if (!initialized) { + if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) { + fprintf(stderr, "Assertion failed AND couldn't init video mode!\n"); + return SDL_ASSERTION_BREAK; /* oh well, crash hard. */ + } + } + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *msg = [NSString stringWithFormat: @@ -242,6 +251,11 @@ [alert addButtonWithTitle:@"Always Ignore"]; const NSInteger clicked = [alert runModal]; [pool release]; + + if (!initialized) { + SDL_QuitSubSystem(SDL_INIT_VIDEO); + } + return (SDL_assert_state) (clicked - NSAlertFirstButtonReturn); }