Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » get_video_bitmap() segfaults when in GFX_GDI mode.

This thread is locked; no one can reply to it. rss feed Print
get_video_bitmap() segfaults when in GFX_GDI mode.
brigham toskin
Member #2,213
April 2002

I didn't see any driver related caveates in the Manual. Had to figure out that it was the video bitmap call that was crashing my app on my own. Guess it makes sense that it wouldn't work, but I thought it would fall over to a regular bitmap like create_system_bitmap() does.

The manual just says it returns NULL of failure, but you can't even test for it unless you caught the exception because it crashes on that call. The GDI driver wont have any direct access to video ram, so yeah, it should fail, but I'd be more inclined to call this a bug than a limitation of the featureset. Really it should fail gracefully, either returning null or a regular bitmap, whichever makes more sense. At the very least, there should be a warning:

Quote:

Video Bitmap in GDI Mode Considered Harmful.

:)

---
I now submit to your flogging.

Evert
Member #794
November 2000
avatar

One would almost get the impression that you think it's intended behavior...

Quote:

Guess it makes sense that it wouldn't work, but I thought it would fall over to a regular bitmap like create_system_bitmap() does.

Check the manual next time before you assume something ;) (I know you did this afterwards).

Quote:

The manual just says it returns NULL of failure, but you can't even test for it unless you caught the exception because it crashes on that call. The GDI driver wont have any direct access to video ram, so yeah, it should fail, but I'd be more inclined to call this a bug than a limitation of the featureset. Really it should fail gracefully, either returning null or a regular bitmap, whichever makes more sense. At the very least, there should be a warning:

We got the point after the first sentence (really!)
Anyway, if a function does not behave as the manual says it should, it's a bug. Now we need someone to fix (and test) it.

As a start, what version of Allegro are you using?

EDIT: It can't be a problem specific to the GDI driver, because that (correctly) doesn't implement specific functions for dealing with video bitmaps. That means that the problem is with the code that deals with subbitmaps of screen, which in turn means that it should show up with other drivers that fall back on this implementation (such as the X11 driver). However, I can't reproduce the problem withthe X11 driver, which is odd.
Please post the smallest example program that reproduces the error, and try linking with the debug version of Allegro to nail down where the crash occurs.

brigham toskin
Member #2,213
April 2002

Allegro 4.2.0, debug, Win XP, VS7.1.

Ok, now I'm stuck here scratching my head and looking quite the fool. When I try to write a minimal startup routine to show you, it's not doing it at all. Tried GFX_GDI and GFX_SAFE and no crash when allocating the first (or any) video bitmap. :-/

Going back to my original code, if I change it by hand to SAFE or GDI, creating a video bitmap does in fact work now, and I can draw to it and flip it to the screen. What doesn't seem to work is creating a second video bitmap (for page flipping or whatever) in safe or GDI. The second one is NULL. I guess whatever code is faking access to video memory only allocates enough to hold the screen dimensions, which means the function is behaving as documented. The basic startup I wrote displays this behavior too:

1 ////////////////////////////////////////////////////////
2 // Breaking Allegro
3 BITMAP *vbmp1, *vbmp2;
4 
5 allegro_init();
6 install_keyboard();
7 install_timer();
8 
9 
10 set_color_depth(8);
11 set_gfx_mode(GFX_SAFE, 640, 480, 0, 0);
12 
13 vbmp1 = create_video_bitmap(640, 480);
14 vbmp2 = create_video_bitmap(640, 480);
15 ASSERT(vbmp1);
16 ASSERT(vbmp2); // <-- FAILS HERE
17 
18 //
19 ////////////////////////////////////////////////////////*/

So I don't know what to tell you guys. Before, I traced my code and it was definitely dying at create_video_bitmap() before any other accesses to the bitmap. Now it all works fine. Perhaps I am mildly retarded afterall.

---
I now submit to your flogging.

Evert
Member #794
November 2000
avatar

Quote:

What doesn't seem to work is creating a second video bitmap (for page flipping or whatever) in safe or GDI. The second one is NULL.

That's what you'd expect. Video bitmaps are allocated as sub-bitmaps of the screen bitmap, and after the first one there is no way to allocate a second one that has the size of the screen and doesn't overlap with the previous one - in other words, you're `out of video memory.'

As to your program not working before, is it possible that you have stray pointers lying around, or didn't compile the entire project before? Glad this issue is solved though. :)

Go to: