- Online Community Forums » Programming Questions » Display stops updating if I change the backbuffer-- What am I doing wrong?

Credits go to SiegeLord for helping out!
This thread is locked; no one can reply to it. rss feed Print
Display stops updating if I change the backbuffer-- What am I doing wrong?
Member #16,498
July 2016

I've been using Allegro for a while, but I've encountered a couple of issues that make me question whether or not I'm using it correctly.

The part of my code that handles the drawing looks like this:

1// Switch to the "scene" bitmap. 2al_set_target_bitmap(__scene_bitmap); 3 4// Draw stuff (objects, GUI, whatever) 5 6// Switch back to the display's buffer. 7al_set_target_bitmap(al_get_backbuffer(__main_display)); 8 9// Draw the "scene" bitmap. 10al_draw_bitmap(__scene_bitmap, 0.0f, 0.0f, NULL); 11 12// Flip display 13al_flip_display();

Everything works as expected... Or so it seems. If I press Ctrl+Alt+Del, then get out of the menu that appears and then go back to the game, the display is no longer updating, but stuck showing the state of the display before I pressed Ctrl+Alt+Del. This also occurs when Windows' UAC is triggered.

It made me wonder if the event loop stopped for some reason, but nope-- it's still chugging along, and the drawing code is being called, it's just no longer being shown on the display.

If I comment out this line...


... It works fine, and the problem no longer occurs, so it has something to do with changing the target bitmap.

On a related note, I use this code to toggle full-screen:

1al_toggle_display_flag(__main_display, ALLEGRO_FULLSCREEN_WINDOW, fullscreen);

When I don't change the target bitmap, this code works as expected (the display is now full-screen). However, if I do change the target bitmap, the display just disappears when this is called and no longer responds. It seems like it does go full-screen (because it blocks all mouse-clicks), it's just invisible and I can't do anything with it.

Any idea what I'm doing wrong, or how I can fix this?

PS: I definitely need to be able to be able to change the target bitmap; commenting that line out permanently isn't an option (my coordinate system among other things relies on this).

Member #11,874
April 2010

What platform are you developing on? Mac, windows, Linux?

Member #16,498
July 2016

Thanks for the reply!

I'm using Windows 8.1 with Allegro 5.20. I haven't verified the issue in Linux, because I don't know what the equivalent of the Ctrl+Alt+Del screen/Windows' UAC pop-ups would be...

Also, if it helps, I put together a full example to show the problem:

1#include <allegro5/allegro.h> 2 3int main() { 4 5 al_init(); 6 7 ALLEGRO_DISPLAY* display = al_create_display(640, 480); 8 ALLEGRO_EVENT_QUEUE* event_queue = al_create_event_queue(); 9 ALLEGRO_TIMER* timer = al_create_timer(1.0f / 60.0f); 10 ALLEGRO_BITMAP* other_bitmap = al_create_bitmap(640, 480); 11 12 al_start_timer(timer); 13 al_register_event_source(event_queue, al_get_timer_event_source(timer)); 14 15 al_clear_to_color(al_map_rgb(0, 0, 0)); 16 al_flip_display(); 17 18 float r = 0.0f, g = 0.0f, b = 0.0f; 19 20 while (true) { 21 22 ALLEGRO_EVENT ev; 23 al_wait_for_event(event_queue, &ev); 24 25 if (ev.type == ALLEGRO_EVENT_TIMER) { 26 27 static bool fade_in = true; 28 if (fade_in) { 29 r += 0.005f; 30 g += 0.005f; 31 b += 0.005f; 32 fade_in = !(r >= 1.0f || g >= 1.0f || b >= 1.0f); 33 } 34 else { 35 r -= 0.005f; 36 g -= 0.005f; 37 b -= 0.005f; 38 fade_in = !(r > 0.0f || g > 0.0f || b > 0.0f); 39 } 40 41 al_set_target_bitmap(other_bitmap); // <-- Problematic! 42 43 al_clear_to_color(al_map_rgb_f(r, g, b)); 44 45 al_set_target_backbuffer(display); 46 47 al_draw_bitmap(other_bitmap, 0.0f, 0.0f, NULL); 48 49 al_flip_display(); 50 51 } 52 53 } 54 55 return 0; 56 57}

As you can see, the screen fades in and out from black-to-white. If I press Ctrl+Alt+Del (which shows the menu with Task Manager, Lock, Switch user, etc.; I don't know what to call it, honestly) and then return to the game, the animation stops updating, even though the drawing code is still being called.



is commented out, the problem no longer occurs.

Another thing that might be worth mentioning is that I was using 5.0.10 prior to updating to 5.20, and this problem didn't occur.

Member #7,827
October 2006

Thanks for the test example, it was very helpful.

This bug is already fixed on the master branch, and will be in the 5.2.1 release (which is coming soon).

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Member #16,498
July 2016

I'm glad to hear that it's already been fixed! I'll keep working around it for now.

Thanks a lot for the quick response.

Go to: