![]() |
|
Allegro crash bug |
Puck6633
Member #4,668
June 2004
|
I was working on a project of mine and came across a curious bug where it would crash on exit. After running it through gdb with a debug compile of allegro I found the the problem seems to be either in allegro/src/mouse.c lines 477 to 488 of show_mouse(), or somewhere in draw_mouse. The problem is that I'm drawing the mouse to a bitmap I created (so I can have objects overlapping the mouse), then blitting that bitmap to the screen. The problem arises at the end of the program, where I free the bitmap I normally draw the mouse to and return from main. This triggers a call to allegro_exit(), which calls shutdown_gfx(), which calls set_gfx_mode(), which in turn calls show_mouse(NULL), which then tries to draw to the destroyed bitmap BEFORE checking if it's argument is NULL. To better illustrate the sequence of function calls, here's the backtrace: And some example C code that triggers the problem:
Compile with 'gcc <filename>.c -o <filename> -lalleg' It's not a serious bug, and calling show_mouse(NULL) before destroying the bitmap prevents the crash, but there it is anyway. [Edit] It just occurred to me that "show_mouse() bug" would have been a much better title, but I can't seem to change the topic, sorry. |
flares
Member #3,463
April 2003
![]() |
All you said was right. i had the same problem, you need to call show_mouse(NULL) before you destroy the bitmap, other wise the mouse updater tries to draw the mouse to a NULL bitmap. I think this happens because the way the mouse updater draws the mouse is only when it changes. if you move the mouse as you are exiting after you destroy the bitmap then it will crash because you try to draw to NULL, and NULL dont like it. [nonnus29]Plus the api is crap ... I'd rather chew broken glass then code with those. |
Evert
Member #794
November 2000
![]() |
Yes, this is a problem. Allegro stores a copy of the screen pointer in teh mouse routines, so that it's possible that the screen is destroyed while the mouse cursor is being drawn onto it. |
Puck6633
Member #4,668
June 2004
|
I'm using 4.1.17 WIP, but it actually doesn't seem to be that the bitmap is being destroyed whiel the mouse is being drawn to it, it seems to be that calling show_mouse(NULL) draws the pointer one last time to the bitmap you last drew to. (At least if I'm reading the code correctly, though the comments seem to confirm it) in particular this bit of code in show_mouse() seems to be at fault: /* Remove the mouse cursor */ if (_mouse_screen) { acquire_bitmap(_mouse_screen); if (gfx_capabilities & GFX_HW_CURSOR) { gfx_driver->hide_mouse(); gfx_capabilities &= ~(GFX_HW_CURSOR|GFX_SYSTEM_CURSOR); } else draw_mouse(TRUE, FALSE); release_bitmap(_mouse_screen); } changing the "else" to an "else if (bmp)" fixed it for me, though I can't say for certain it won't cause other problems, particlarly with hardware cursors (which I can't test). |
|