ObjGameKit  Check-in [4719f25709]

Overview
Comment: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.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4719f257098862d724c5e3cec9f5db35bd4ee090913e5361a90c33cfd9c23ca4
User & Date: js on 2012-08-26 12:17:52
Original User & Date: js on 2012-08-26 12:17:53
Other Links: manifest | tags
Context
2012-08-26
12:17
Remove ogk_event_type_t, which was unused anyway. check-in: c7c26ea8cf user: js tags: trunk
12:17
Only call al_*_destroy if Allegro is initialized. check-in: 4719f25709 user: js tags: trunk
10:09
Use flags for -[OGKDisplay init...]. check-in: 40c2d53ff0 user: js tags: trunk
Changes

Modified src/OGKBitmap.m from [d4949e0576] to [ffce6aad92].

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

@implementation OGKBitmap
+ (void)initialize
{
	if (self != [OGKBitmap class])
		return;

	if (!al_install_system(ALLEGRO_VERSION_INT, NULL) ||
	    !al_init_image_addon())
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
}

+ (void)setTarget: (id)target
{
	if ([target isKindOfClass: [OGKDisplay class]])







<
|







28
29
30
31
32
33
34

35
36
37
38
39
40
41
42

@implementation OGKBitmap
+ (void)initialize
{
	if (self != [OGKBitmap class])
		return;


	if (!al_init() || !al_init_image_addon())
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
}

+ (void)setTarget: (id)target
{
	if ([target isKindOfClass: [OGKDisplay class]])
74
75
76
77
78
79
80






81
82
83
84
85
86
87
88
89
90
91

	if (bitmap == NULL)
		@throw [OFInitializationFailedException
		    exceptionWithClass: [self class]];

	return self;
}







- (void)drawAtPosition: (of_point_t)position
{
	al_draw_bitmap(bitmap, position.x, position.y, 0);
}

- (ALLEGRO_BITMAP*)OGK_allegroBitmap
{
	return bitmap;
}
@end







>
>
>
>
>
>











73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

	if (bitmap == NULL)
		@throw [OFInitializationFailedException
		    exceptionWithClass: [self class]];

	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);
}

- (ALLEGRO_BITMAP*)OGK_allegroBitmap
{
	return bitmap;
}
@end

Modified src/OGKDisplay.m from [c9b84695dd] to [2b13daa365].

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

@implementation OGKDisplay
+ (void)initialize
{
	if (self != [OGKDisplay class])
		return;

	if (!al_install_system(ALLEGRO_VERSION_INT, NULL))
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];

	mutex = [[OFMutex alloc] init];
	displays = [[OFMutableArray alloc] init];
	allegroDisplays = [[OFDataArray alloc]
	    initWithItemSize: sizeof(ALLEGRO_DISPLAY*)];







|







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

@implementation OGKDisplay
+ (void)initialize
{
	if (self != [OGKDisplay class])
		return;

	if (!al_init())
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];

	mutex = [[OFMutex alloc] init];
	displays = [[OFMutableArray alloc] init];
	allegroDisplays = [[OFDataArray alloc]
	    initWithItemSize: sizeof(ALLEGRO_DISPLAY*)];
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

		[allegroDisplays removeItemAtIndex: index];
		[displays removeObjectAtIndex: index];
	} @finally {
		[mutex unlock];
	}

	if (display != NULL)
		al_destroy_display(display);
}

- (void)setWindowTitle: (OFString*)title
{
	al_set_window_title(display,
	    [title cStringWithEncoding: OF_STRING_ENCODING_NATIVE]);







|







104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

		[allegroDisplays removeItemAtIndex: index];
		[displays removeObjectAtIndex: index];
	} @finally {
		[mutex unlock];
	}

	if (display != NULL && al_is_system_installed())
		al_destroy_display(display);
}

- (void)setWindowTitle: (OFString*)title
{
	al_set_window_title(display,
	    [title cStringWithEncoding: OF_STRING_ENCODING_NATIVE]);

Modified src/OGKEventQueue.m from [7219e86adc] to [84dbf1da64].

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

52
53
54
55
56
57
58
59
@synthesize delegate;

+ (void)initialize
{
	if (self != [OGKEventQueue class])
		return;

	if (!al_install_system(ALLEGRO_VERSION_INT, NULL))
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
}

- init
{
	self = [super init];

	eventQueue = al_create_event_queue();

	return self;
}

- (void)dealloc
{

	al_destroy_event_queue(eventQueue);
}

- (void)handleNextEvent
{
	OGKEvent *event = [[OGKEvent alloc] init];
	ALLEGRO_EVENT *allegroEvent = [event OGK_allegroEvent];








|















>
|







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
@synthesize delegate;

+ (void)initialize
{
	if (self != [OGKEventQueue class])
		return;

	if (!al_init())
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
}

- init
{
	self = [super init];

	eventQueue = al_create_event_queue();

	return self;
}

- (void)dealloc
{
	if (al_is_system_installed())
		al_destroy_event_queue(eventQueue);
}

- (void)handleNextEvent
{
	OGKEvent *event = [[OGKEvent alloc] init];
	ALLEGRO_EVENT *allegroEvent = [event OGK_allegroEvent];

Modified test/TestMain.m from [a7dbf6df22] to [28b7846922].

112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
	for (running = YES; running;) {
		@autoreleasepool {
			[self handleEvents];
			[self draw];
		}
	}
}

- (void)applicationWillTerminate
{
	/* Make sure they don't get deallocated after al_uninstall_system() */
	display = nil;
	eventQueue = nil;

	al_uninstall_system();
}
@end







<
<
<
<
<
<
<
<
<

112
113
114
115
116
117
118









119
	for (running = YES; running;) {
		@autoreleasepool {
			[self handleEvents];
			[self draw];
		}
	}
}









@end