Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » A5 program doesn't work after computer suspend

This thread is locked; no one can reply to it. rss feed Print
A5 program doesn't work after computer suspend
Ashteth
Member #3,310
March 2003
avatar

My Allegro 5.09 program does not work correctly after a computer suspend. I suspect this is a problem with my event loop but I may be incorrect. Any suggestions on how to address this issue?

Trent Gamblin
Member #261
April 2000
avatar

Can you describe the problem? If it seems it's hanging maybe you didn't stop your timers and they built up a ton of events or something.

Ashteth
Member #3,310
March 2003
avatar

After a system suspend (I close my laptop monitor), the Allegro program displays the static image that it last displayed but sprites do not update, the mouse is unresponsive etc. In other words, what you indicated makes a lot of sense: the event queue may be built up and cannot flush. Below is my main loop (with comments not present in the actual code) to indicate what is going on. You will also note that I am using AGUI, though disabling AGUI seems to have no effect on the problem.

I guess the questions are: is there anything I can add to flush the queue after a system suspend? And: would updating to a version of Allegro after 5.09 solve this problem?

Thanks

#SelectExpand
1 while(bMainLoop) 2 { 3 ALLEGRO_EVENT ev; 4 al_wait_for_event(m_qEventQueue, &ev); 5 // Process event in AGUI. 6 inputHandler->processEvent(ev); 7 switch(ev.type) 8 { 9 case ALLEGRO_EVENT_TIMER: 10 { 11 // Record Time 12 m_dSimTime = al_get_time(); 13 m_dElapsedTime = m_dSimTime - m_dLastTime; 14 m_dLastTime = m_dSimTime; 15 16 // Force redraw after event is handled. 17 bRedraw = true; 18 19 // Update mouse location. 20 g_cMouse.setCaptured(false); 21 g_cMouse.updateMouseDrag(); 22 23 // Update scenegraph 24 g_cSceneGraph.update(m_dSimTime, m_dElapsedTime); 25 26 // Update timed function callback pipe. 27 // C style callback functions are executed based 28 // on timer and then erased. 29 g_cPlan.update(m_dSimTime); 30 break; 31 } 32 case ALLEGRO_EVENT_DISPLAY_CLOSE: 33 { 34 bMainLoop = false; 35 break; 36 } 37 case ALLEGRO_EVENT_MOUSE_AXES: 38 case ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY: 39 { 40 // Record mouse position. 41 m_iMouseX = ev.mouse.x; 42 m_iMouseY = ev.mouse.y; 43 a2dVector vPos(ev.mouse.x, ev.mouse.y); 44 g_cMouse.setPos(vPos); 45 break; 46 } 47 case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN: 48 { 49 if(1 == ev.mouse.button) 50 { 51 g_cMouse.setLeftDown(true); 52 } 53 if(2 == ev.mouse.button) 54 { 55 g_cMouse.setRightDown(true); 56 } 57 break; 58 } 59 case ALLEGRO_EVENT_MOUSE_BUTTON_UP: 60 { 61 if(1 == ev.mouse.button) 62 { 63 g_cMouse.setLeftDown(false); 64 } 65 if(2 == ev.mouse.button) 66 { 67 g_cMouse.setRightDown(false); 68 } 69 break; 70 } 71 72 case ALLEGRO_EVENT_DISPLAY_EXPOSE: 73 { 74 bRedraw = true; 75 break; 76 } 77 default: 78 { 79 break; 80 } 81 } 82 83 if(bRedraw && al_is_event_queue_empty(m_qEventQueue)) 84 { 85 bRedraw = false; 86 al_set_target_backbuffer(m_qDisplay); 87 al_clear_to_color(al_map_rgb(0,0,0)); 88 89 // Draw scenegraph 90 g_cSceneGraph.draw(); 91 92 // Draw gui 93 gui->logic(); 94 gui->render(); 95 96 al_flip_display(); 97 } 98 }

Trent Gamblin
Member #261
April 2000
avatar

There is nothing in Allegro that will tell you the system has suspended or resumed, so you could try checking for a large jump in time and if that happens flush the event queue?

Thomas Fjellstrom
Member #476
June 2000
avatar

Is there a chance he'll get a DISPLAY_LOST event?

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Trent Gamblin
Member #261
April 2000
avatar

Only if he's using D3D.

Ashteth
Member #3,310
March 2003
avatar

Anyone know how to purge the event buffer so I can test some of these theories out? I will most likely come back to this problem later. It's really more of a minor annoyance and I have more important things to work on. I'm surprised no one else seems to have come across this problem. Thanks.

Trent Gamblin
Member #261
April 2000
avatar

Ashteth
Member #3,310
March 2003
avatar

Flushing the buffer after 10 minutes of inactivity seems to solve the problem. Thanks. Now all I have to do is figure out why some of the bitmaps seem to get corrupted after a suspend.

Trent Gamblin
Member #261
April 2000
avatar

Are you using D3D? In theory you should only get corrupted bitmaps with D3D + using ALLEGRO_NO_PRESERVE_TEXTURE.

Go to: