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.
This commit is contained in:
parent
c2baff8cd6
commit
f32ef7ee28
4 changed files with 12 additions and 15 deletions
|
@ -32,8 +32,7 @@ ogk_color_t OGK_COLOR_BLACK = { 0, 0, 0, 1 };
|
||||||
if (self != [OGKBitmap class])
|
if (self != [OGKBitmap class])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!al_install_system(ALLEGRO_VERSION_INT, NULL) ||
|
if (!al_init() || !al_init_image_addon())
|
||||||
!al_init_image_addon())
|
|
||||||
@throw [OFInitializationFailedException
|
@throw [OFInitializationFailedException
|
||||||
exceptionWithClass: self];
|
exceptionWithClass: self];
|
||||||
}
|
}
|
||||||
|
@ -79,6 +78,12 @@ ogk_color_t OGK_COLOR_BLACK = { 0, 0, 0, 1 };
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)dealloc
|
||||||
|
{
|
||||||
|
if (bitmap != NULL && al_is_system_installed())
|
||||||
|
al_destroy_bitmap(bitmap);
|
||||||
|
}
|
||||||
|
|
||||||
- (void)drawAtPosition: (of_point_t)position
|
- (void)drawAtPosition: (of_point_t)position
|
||||||
{
|
{
|
||||||
al_draw_bitmap(bitmap, position.x, position.y, 0);
|
al_draw_bitmap(bitmap, position.x, position.y, 0);
|
||||||
|
|
|
@ -30,7 +30,7 @@ static OFDataArray *allegroDisplays = nil;
|
||||||
if (self != [OGKDisplay class])
|
if (self != [OGKDisplay class])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!al_install_system(ALLEGRO_VERSION_INT, NULL))
|
if (!al_init())
|
||||||
@throw [OFInitializationFailedException
|
@throw [OFInitializationFailedException
|
||||||
exceptionWithClass: self];
|
exceptionWithClass: self];
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ static OFDataArray *allegroDisplays = nil;
|
||||||
[mutex unlock];
|
[mutex unlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (display != NULL)
|
if (display != NULL && al_is_system_installed())
|
||||||
al_destroy_display(display);
|
al_destroy_display(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ static int mouse_retain_count = 0;
|
||||||
if (self != [OGKEventQueue class])
|
if (self != [OGKEventQueue class])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!al_install_system(ALLEGRO_VERSION_INT, NULL))
|
if (!al_init())
|
||||||
@throw [OFInitializationFailedException
|
@throw [OFInitializationFailedException
|
||||||
exceptionWithClass: self];
|
exceptionWithClass: self];
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ static int mouse_retain_count = 0;
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
{
|
{
|
||||||
|
if (al_is_system_installed())
|
||||||
al_destroy_event_queue(eventQueue);
|
al_destroy_event_queue(eventQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
@end
|
||||||
|
|
Reference in a new issue