Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » maximum size to al_create_bitmap

This thread is locked; no one can reply to it. rss feed Print
maximum size to al_create_bitmap
The Master
Member #4,498
April 2004
avatar

Allegro5 question:

I'm working on loading a tile set into a single bitmap, and then drawing regions of this bitmap as required. It was the simplest and most straightforward approach.

But I seem to be having a problem. I've saved the tile set into a custom format made with TileStudio (which is awesome by the way), and so I've written code that loads it into an Allegro5 bitmap structure. I do this by creating a new bitmap, and then loading the pixel colour components from the file and using al_put_pixel. Now I know this all works, because I've seen it.

But it gets to when I'm actually creating the bitmap. Sometimes (most of the time but not all) al_create_bitmap will cause a weird exception to be thrown elsewhere in the program. That is, the code will execute until al_create_bitmap, and then it'll throw an exception. But the call stack will in fact point to a different part of the program (some where inside the NSApplication object - I'm using Mac OS X).

I've concluded, but I'm not entirely sure, that this is being caused by me asking for a massive bitmap. 48 tiles, each tile 32x32x32bits. So I was curious if there is an upper limit on the permitted size of a bitmap (independent of the available memory).

Let me know :)

We can only do what we feel is right each moment as we live it.

Evert
Member #794
November 2000
avatar

That is, the code will execute until al_create_bitmap, and then it'll throw an exception. But the call stack will in fact point to a different part of the program (some where inside the NSApplication object - I'm using Mac OS X).

That's the main thread, but your program runs from a secondary thread. You need to switch to one of the other threads to find the correct point where the program crashes (I can never quite remember which thread I want, but you can easily tell by trying them all because most of the tracebacks will not make sence).

Quote:

I've concluded, but I'm not entirely sure, that this is being caused by me asking for a massive bitmap. 48 tiles, each tile 32x32x32bits. So I was curious if there is an upper limit on the permitted size of a bitmap (independent of the available memory).

Yes, if it's a video bitmap, it must be smaller than the largest texture size. If you do a 32 by 48*32 bitmap, you may overrun that. This is less likely if you do 3*32 by 16*32.

Matthew Leverton
Supreme Loser
January 1999
avatar

You can query the maximum size allowed via al_get_new_display_option with ALLEGRO_MAX_BITMAP_SIZE.

Evert said:

if you do a 32 by 48*32 bitmap, you may overrun that. This is less likely if you do 3*32 by 16*32.

In other words, make your tile bitmap square. The longest side is what determines whether or not it will fit into a video bitmap. The same card that doesn't support 1025x32 might support 1024x1024.

The Master
Member #4,498
April 2004
avatar

Well, i think this is worthy of a bug report in the MacOSX port. i'm still having this problem.

[EDIT] it's not just appearing in al_create_bitmap. sometimes it shows up in al_set_target_bitmap. sometimes it shows up in al_fclose.

We can only do what we feel is right each moment as we live it.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Post backtraces of when it occurs, and try examining local variables in the line of code that crashes. Also, run a debug version of your program linked to the debugging version of Allegro. That will create an allegro.log file that may have some clues as well.

Evert
Member #794
November 2000
avatar

Well, i think this is worthy of a bug report in the MacOSX port. i'm still having this problem.

There's no OS X specific code in al_create_bitmap(), it's the same code used on other OpenGL-based ports. So if there is a problem with it, it should show up there too.

Quote:

it's not just appearing in al_create_bitmap. sometimes it shows up in al_set_target_bitmap. sometimes it shows up in al_fclose.

That sounds like you are overwriting memory that you shouldn't due to a bad pointer.

The Master
Member #4,498
April 2004
avatar

ok, i'll triple check my loading and allocation. might use vectors or something instead of the new operator

[EDIT] Now this is freaking weird. I changed my data allocation methods from 'new' to 'std::vector'. and it still shows the same bad alloc error: exact same line number, different code.

We can only do what we feel is right each moment as we live it.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Go to: