al_draw_bitmap fails to run on threads other than the parent thread

I'm thought it'd be wise to have the drawing code of my game run on a separate thread for obvious performance reasons. After several attempts at this i decided to experiment and just run calls of al_draw_bitmap on a separate thread. Here is the code I used for this:

1void draw_video_frame(ALLEGRO_BITMAP * frame) { al_draw_bitmap(frame, 0, 0, 0); } 2 3void * t_draw_video_frame(ALLEGRO_THREAD * thread, void * arg) 4 { 5 ALLEGRO_BITMAP * frame = (ALLEGRO_BITMAP *) arg; 6 draw_video_frame(frame); 7 return NULL; 8 } 9 10void stream_video(Video * video) 11 { 12 load_frame(video); 13 video_frame_step(video); 14 ALLEGRO_THREAD * thread = al_create_thread(t_draw_video_frame, (void *) video->last_stepped_frame); 15 al_start_thread(thread); 16 al_join_thread(thread, NULL); 17 destroy_video_frame(video->prev_stepped_frame); 18 al_destroy_thread(thread); 19 }

This fails with the error: Assertion failed: (src), function al_copy_transform, file /Users/iam_donald/Downloads/allegro/src/transformations.c, line 32.

Calling draw_video_frame() works. My question is: Is this behavior by design or I am I doing something silly here? Currently this behavior doesn't allow running any chunk of code with calls to al_draw_bitmap on a thread other than parent thread.

Matthew Leverton

See al_set_target_bitmap().


A single display cannot be current for multiple threads simultaneously. If you need to release a display, so it is not current for the calling thread, call al_set_target_bitmap(NULL);

So set the parent's target bitmap to NULL and set the child's to the display's back buffer.


That explains it. Thanks.

Thread #610506. Printed from