Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Memory bitmaps fail in Allegro-4.9.8

This thread is locked; no one can reply to it. rss feed Print
Memory bitmaps fail in Allegro-4.9.8
Todd Cope
Member #998
November 2000
avatar

Today I downloaded Revision 11566 from the snapshot. The build went smooth so I installed it and rebuilt my game linking to it instead of 4.7.1. Aside from having to change my fshook calls to match the API changes everything worked fine until it got to the point in my code where I am using a memory bitmap.

When I use this code:

  al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
  fimage = al_iio_load(fn);
  ...

my program crashes at "fimage = al_iio_load(fn)."

If I comment out "al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP)" the program runs. I looked in the examples and found "ex_membpm" so I tried it and sure enough it crashes. I tried "ex_membmp" in 4.9.7.1 just to be sure and it works there.

Bottom line is memory bitmaps do not work in the current SVN version.

SiegeLord
Member #7,827
October 2006
avatar

What system are you testing this on?

Incidentally, everything works fine on my system (Linux).

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

Todd Cope
Member #998
November 2000
avatar

Windows

I've been trying other snapshots to see if I can pinpoint where the problem came up but so far all have the same issue.

Edit: I got the oldest snapshot available (11398) and it still crashes on memory bitmaps.

ImLeftFooted
Member #3,935
October 2003
avatar

I hear ginseng helps with that... or maybe a memory game.

Trent Gamblin
Member #261
April 2000
avatar

Memory bitmaps work fine for me with the latest svn and I haven't noticed them not working in my game, which I've kept up to date with Allegro. Maybe you can pinpoint the problem a little further so we can fix it? A backtrace might be helpful.

Todd Cope
Member #998
November 2000
avatar

I built the debug version and got this when I ran "ex_membmp:"
Assert failed at line 696 of C:\Programming\Libraries\allegro-4.9\src\pixels.c
I'm currently looking into how to use gdb to see if I can get more information.

Edit: gdb doesn't produce a backtrace when I run "ex_membmp" through it, it just shows the same error I quoted above.

Edit2: I've looked deep into the source and I think the issue is with this function:

1static ALLEGRO_BITMAP *_al_create_memory_bitmap(int w, int h)
2{
3 ALLEGRO_BITMAP *bitmap;
4 int pitch;
5 int format = al_get_new_bitmap_format();
6
7 /* Pick an appropriate format if the user is vague */
8 switch (format) {
9 case ALLEGRO_PIXEL_FORMAT_ANY_NO_ALPHA:
10 case ALLEGRO_PIXEL_FORMAT_ANY_32_NO_ALPHA:
11 format = ALLEGRO_PIXEL_FORMAT_XRGB_8888;
12 break;
13 case ALLEGRO_PIXEL_FORMAT_ANY_WITH_ALPHA:
14 case ALLEGRO_PIXEL_FORMAT_ANY_32_WITH_ALPHA:
15 format = ALLEGRO_PIXEL_FORMAT_ARGB_8888;
16 break;
17 case ALLEGRO_PIXEL_FORMAT_ANY_15_NO_ALPHA:
18 format = ALLEGRO_PIXEL_FORMAT_RGB_555;
19 break;
20 case ALLEGRO_PIXEL_FORMAT_ANY_16_NO_ALPHA:
21 format = ALLEGRO_PIXEL_FORMAT_RGB_565;
22 break;
23 case ALLEGRO_PIXEL_FORMAT_ANY_16_WITH_ALPHA:
24 format = ALLEGRO_PIXEL_FORMAT_ARGB_4444;
25 break;
26 case ALLEGRO_PIXEL_FORMAT_ANY_24_NO_ALPHA:
27 format = ALLEGRO_PIXEL_FORMAT_RGB_888;
28 break;
29 case ALLEGRO_PIXEL_FORMAT_ANY_15_WITH_ALPHA:
30 case ALLEGRO_PIXEL_FORMAT_ANY_24_WITH_ALPHA:
31 /* We don't support any 24 or 15 bit formats with alpha. */
32 return NULL;
33 default:
34 break;
35 }
36 
37 bitmap = _AL_MALLOC(sizeof *bitmap);
38 memset(bitmap, 0, sizeof(*bitmap));
39 bitmap->size = sizeof(*bitmap);
40 
41 pitch = w * al_get_pixel_size(format);
42 
43 bitmap->vt = NULL;
44 bitmap->format = format;
45 bitmap->flags = al_get_new_bitmap_flags() | ALLEGRO_MEMORY_BITMAP;
46 bitmap->w = w;
47 bitmap->h = h;
48 bitmap->pitch = pitch;
49 bitmap->display = NULL;
50 bitmap->locked = false;
51 bitmap->cl = bitmap->ct = 0;
52 bitmap->cr = w;
53 bitmap->cb = h;
54 bitmap->parent = NULL;
55 bitmap->xofs = bitmap->yofs = 0;
56 // FIXME: Of course, we do need to handle all the possible different formats,
57 // this will easily fill up its own file of 1000 lines, but for now,
58 // RGBA with 8-bit per component is hardcoded.
59 bitmap->memory = _AL_MALLOC(pitch * h);
60 return bitmap;
61}

Particularly, when format is "ALLEGRO_PIXEL_FORMAT_ANY" (which it is by default from what I can tell) a detailed pixel format is not selected. There should be case for "ALLEGRO_PIXEL_FORMAT_ANY" although I don't really know what should go there.

Edit3: I set the pixel format to ALLEGRO_PIXEL_FORMAT_ANY_WITH_ALPHA before the memory bitmaps in my program and the crash is gone so I believe I am right about where the bug lies.

Trent Gamblin
Member #261
April 2000
avatar

Thanks for tracking that down. It should be fixed in SVN, if that was all that was wrong.

Todd Cope
Member #998
November 2000
avatar

Works fine now.

Matthew Leverton
Supreme Loser
January 1999
avatar

SVN log said:

Added ALLEGRO_PIXEL_FORMAT_ANY.
Warning: Adding a new pixel format is a painfull process. There's a lot of places to update
and it's possible I've missed some.

Todd Cope
Member #998
November 2000
avatar

I see, when ALLEGRO_PIXEL_FORMAT_ANY was added, the default pixel format was changed from ALLEGRO_PIXEL_FORMAT_ANY_WITH_ALPHA. Is there a reason the default is to not use alpha? I think it breaks continuity a little. When I load an image with an alpha channel as a display bitmap the alpha channel is enabled there, but when I switch to memory bitmaps suddenly I have to force the alpha channel with an extra function call.

Elias
Member #358
May 2000

I agree, we should have a format with alpha as default - but probably there's some good reason it was changed.

--
"Either help out or stop whining" - Evert

Matthew Leverton
Supreme Loser
January 1999
avatar

ALLEGRO_PIXEL_FORMAT_ANY is not ALLEGRO_PIXEL_FORMAT_ANY_NO_ALPHA.

See <http://www.allegro.cc/forums/thread/598599>.

Elias
Member #358
May 2000

Ok, so ALLEGRO_PIXEL_FORMAT_ANY should still create a bitmap with alpha for memory bitmaps - only if no alpha is available (as can happen when creating the "screen" bitmap) it will not fail because of that and use a bitmap without alpha.

--
"Either help out or stop whining" - Evert

Todd Cope
Member #998
November 2000
avatar

In regards to creating new bitmaps ALLEGRO_PIXEL_FORMAT_ANY and ALLEGRO_PIXEL_FORMAT_ANY_NO_ALPHA are identical.

bitmap_new.c said:

      case ALLEGRO_PIXEL_FORMAT_ANY:
      case ALLEGRO_PIXEL_FORMAT_ANY_NO_ALPHA:
      case ALLEGRO_PIXEL_FORMAT_ANY_32_NO_ALPHA:
         format = ALLEGRO_PIXEL_FORMAT_XRGB_8888;
         break;

Edit: what Elias said.

Trent Gamblin
Member #261
April 2000
avatar

You're right, I put it in the wrong place. Fixed again.

Matthew Leverton
Supreme Loser
January 1999
avatar

But will ALLEGRO_PIXEL_FORMAT_ARGB_8888 fail in places where ALLEGRO_PIXEL_FORMAT_XRGB_8888 does not? If so, then the decision is conditional.

Trent Gamblin
Member #261
April 2000
avatar

Probably not for normal bitmaps. The only issue is display backbuffers, which in many cases cannot have alpha in them. The D3D code chooses smartly in both cases (at least it's supposed to).

Go to: