From f32ef7ee28af4ea176b3da3e0df11fe7e35293cd Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Sun, 26 Aug 2012 13:29:53 +0200 Subject: [PATCH] Only call al_*_destroy if Allegro is initialized. Otherwise, it would crash if al_uinstall_system() has already been called. Handling it this way eliminates the need to dealloc all objects before calling al_uninstall_system(), which meant that it was the users repsonsibility to call al_uninstall_system() after the user made sure all objects are deallocated. Now the user does not get to see any al_*() function. --- src/OGKBitmap.m | 9 +++++++-- src/OGKDisplay.m | 4 ++-- src/OGKEventQueue.m | 5 +++-- test/TestMain.m | 9 --------- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/OGKBitmap.m b/src/OGKBitmap.m index df47771..bd22216 100644 --- a/src/OGKBitmap.m +++ b/src/OGKBitmap.m @@ -32,8 +32,7 @@ ogk_color_t OGK_COLOR_BLACK = { 0, 0, 0, 1 }; if (self != [OGKBitmap class]) return; - if (!al_install_system(ALLEGRO_VERSION_INT, NULL) || - !al_init_image_addon()) + if (!al_init() || !al_init_image_addon()) @throw [OFInitializationFailedException exceptionWithClass: self]; } @@ -79,6 +78,12 @@ ogk_color_t OGK_COLOR_BLACK = { 0, 0, 0, 1 }; return self; } +- (void)dealloc +{ + if (bitmap != NULL && al_is_system_installed()) + al_destroy_bitmap(bitmap); +} + - (void)drawAtPosition: (of_point_t)position { al_draw_bitmap(bitmap, position.x, position.y, 0); diff --git a/src/OGKDisplay.m b/src/OGKDisplay.m index ee97c0d..645cb46 100644 --- a/src/OGKDisplay.m +++ b/src/OGKDisplay.m @@ -30,7 +30,7 @@ static OFDataArray *allegroDisplays = nil; if (self != [OGKDisplay class]) return; - if (!al_install_system(ALLEGRO_VERSION_INT, NULL)) + if (!al_init()) @throw [OFInitializationFailedException exceptionWithClass: self]; @@ -108,7 +108,7 @@ static OFDataArray *allegroDisplays = nil; [mutex unlock]; } - if (display != NULL) + if (display != NULL && al_is_system_installed()) al_destroy_display(display); } diff --git a/src/OGKEventQueue.m b/src/OGKEventQueue.m index b28e498..8a8c537 100644 --- a/src/OGKEventQueue.m +++ b/src/OGKEventQueue.m @@ -33,7 +33,7 @@ static int mouse_retain_count = 0; if (self != [OGKEventQueue class]) return; - if (!al_install_system(ALLEGRO_VERSION_INT, NULL)) + if (!al_init()) @throw [OFInitializationFailedException exceptionWithClass: self]; } @@ -49,7 +49,8 @@ static int mouse_retain_count = 0; - (void)dealloc { - al_destroy_event_queue(eventQueue); + if (al_is_system_installed()) + al_destroy_event_queue(eventQueue); } - (void)handleNextEvent diff --git a/test/TestMain.m b/test/TestMain.m index 0641a34..c72736c 100644 --- a/test/TestMain.m +++ b/test/TestMain.m @@ -116,13 +116,4 @@ OF_APPLICATION_DELEGATE(TestMain) } } } - -- (void)applicationWillTerminate -{ - /* Make sure they don't get deallocated after al_uninstall_system() */ - display = nil; - eventQueue = nil; - - al_uninstall_system(); -} @end