From: Sherjeel A. <she...@ya...> - 2009-03-28 16:51:38
|
Hi Allegro is not just only a game programming library but also an excellent graphics library. I've Allegro 4.2.2 built with VS2005 SP1. I've WinXP SP3 on a Pentium4 2.26Ghz. However I'm facing an issue running the Allegro applications in GDI mode. A small program (much more rarely) exhibiting the behavior is as following. It is also strange that more lengthy code produces more chances of crash. #include <allegro.h> #include <winalleg.h> // For including <window.h> volatile bool bCloseBttnPressed = false; void close_button_handler(void) { bCloseBttnPressed = true; } int main(void) { int i; int my_key; BITMAP *pBmpMiceSprite; BITMAP *pBmpChar[2]; allegro_init(); install_timer(); install_keyboard(); install_mouse(); set_gdi_color_format(); set_color_depth(desktop_color_depth()); set_gfx_mode(GFX_GDI, 750, 500, 0, 0); set_display_switch_mode(SWITCH_BACKGROUND); // Don't pause when in background //set_display_switch_mode(SWITCH_BACKAMNESIA); set_window_title("My Allegro Application"); set_close_button_callback(close_button_handler); show_mouse(screen); pBmpMiceSprite = create_bitmap(32,32); rectfill(pBmpMiceSprite,0,0,31,31,bitmap_mask_color(pBmpMiceSprite)); for(i = 1; i < 15; i += 3) circle(pBmpMiceSprite,15,15,i,makecol(255,0,0)); pBmpChar[0] = create_bitmap(750,500); rectfill(pBmpChar[0],0,0,749,499,makecol(0,255,0)); pBmpChar[1] = create_bitmap(750,500); rectfill(pBmpChar[1],0,0,749,499,makecol(0,0,255)); set_mouse_sprite(pBmpMiceSprite); i = 0; my_key = NULL; while( (my_key != 27) && (bCloseBttnPressed == false)) { scare_mouse(); acquire_screen(); blit(pBmpChar[i],screen,0,0,0,0,750,500); release_screen(); unscare_mouse(); rest(1); // Play nice with OS Scheduler i = (i+1) % 2; if(keypressed()) my_key = (readkey() & 0xFF); // Interested in only ASCII } set_mouse_sprite(NULL); // Change back allegro's arrow pointer destroy_bitmap(pBmpMiceSprite); destroy_bitmap(pBmpChar[0]); destroy_bitmap(pBmpChar[1]); return 0; } END_OF_MAIN() The application sometimes (though very rare) hangs when it exits or when I switch to some other application. I've tried to debug the situation. Many many times it is deep inside windows own system files like ntdll.dll but sometimes I catch it in the following: When exiting application: wwnd.c (Allegro Source) - line number 470, result = MsgWaitForMultipleObjects(_win_input_events, _win_input_event_id, FALSE, INFINITE, QS_ALLINPUT); When switching application and also sometimes when exiting: thread.c (C Runtime Library) - line number 293, ( (void(__CLRCALL_OR_CDECL *)(void *))(((_ptiddata)ptd)->_initaddr) ) ( ((_ptiddata)ptd)->_initarg ); I've brought the application on other systems but with varying frequency the problem persists there too. I was thinking there might be something wrong by me building the allegro but the problem persists even with the pre-built allegro libraries downloaded from the Allegro Website. I've also tried versions 4.2.0 and 4.3.10 but found no difference. As I've already stated that it appears very rare but I want to avoid this situation to write quality software. What are your recommendations? Please share. |