Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » sub bitmaps

This thread is locked; no one can reply to it. rss feed Print
sub bitmaps
Neil Walker
Member #210
April 2000
avatar

Hello,
I've created a bitmap that can be either memory, video or system. I then use create_sub_bitmap() to create sub bitmaps. All is well and everything displays ok.

When I destroy the sub bitmaps all is well for video and memory bitmaps, but when I call destroy_bitmap on the first sub bitmap where the master is of type System Bitmap, the program crashes.

All the pointers are correct as they both display ok and video/memory works fine. My log shows all is well too:

New video bitmap is 0x3d9de0
Bitmap is sub bitmap of master 0x3d9de0 and created image is 0x3dc138
Sub bitmap destroyed 0x3dc138
sheet_grid.bmp:0x3d9de0 destroyed

This is the output for video and memory bitmaps, but when I use system bitmaps it crashes on the first destroy.

Anyone got a clue as to why?

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

ReyBrujo
Moderator
January 2001
avatar

Compile with debug support, and use gdb to create a backtrace. Post it here to see if there is an error.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Gideon Weems
Member #3,925
October 2003

Do you first...

  • Destroy the parent?

</li>
Those are my only guesses until you do what Rey says.

Onewing
Member #6,152
August 2005
avatar

This might be of little help. You can use:

int is_system_bitmap(BITMAP *bmp);

to see if the sub_bitmap is a sub of the system bitmap you've created. I'd be curious as to whether the sub_bitmap was "subbing" correctly. It most likely is.

I've had a problem somewhat like this before, but can't remember what it was. When I get home, I'll look to see if I can find the old problem. :)

------------
Solo-Games.org | My Tech Blog: The Digital Helm

Evert
Member #794
November 2000
avatar

Can you post a small sample programme that duplicates the problem?
Not that I can test it myself (system bitmaps are really a Windows thing, as far as Allegro is concerned right now), but others might be able to.

Neil Walker
Member #210
April 2000
avatar

Hello,
1. How does one create a backtrace? I mainly use MSVC but have mingw installed also.

2. The parent wasn't destroyed first and the graphics mode hasn't changed. As I said it works ok when it is a video or memory bitmap.

3. Yes, it is a system bitmap, I already checked the output code

4. Well it'll be hard to post a little program as it's part of a very big program :)

Thanks.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Evert
Member #794
November 2000
avatar

Quote:

4. Well it'll be hard to post a little program as it's part of a very big program

Sure, but you can write a small programme that creates a system bitmap with child and destroys both of those. Does that reproduce the error? If not, start adding things like video bitmaps along with the system bitmaps and see if that makes the error appear, etc...

ReyBrujo
Moderator
January 2001
avatar

Do you know how to compile with MinGW? Does your program works with MinGW? It also crash?

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Neil Walker
Member #210
April 2000
avatar

[edit]I've put some outputting to the screen of the image being deleted and I guess I must be doing something wrong as it looks like the image being destroyed is (bizarrely) a different part of the master image. It is doing this for video and system bitmaps but memory ones are ok. I don't really get this as just before I exit I am ouputting the same images and they display ok!
[/edit]

I've ran debug from MSVC and it is crashing where I said, at: destroy_bitmap(Image). Checking the value of Image (which is a BITMAP pointer) it seems valid to me and it's address matches that when it was created so it's pointing to the same piece of memory:

- Image 0x012f0b20 {w=24 h=24 clip=-1 ...} BITMAP *
w 24 int
h 24 int
clip -1 int
cl 0 int
cr 24 int
ct 0 int
cb 24 int
+ vtable 0x100eaa60 {color_depth=32 mask_color=16711935 unwrite_bank=0x1009524c ...} GFX_VTABLE *
write_bank 0x10095230 void *
read_bank 0x10095230 void *
dat 0x00000000 void *
id 1610612737 unsigned long
extra 0x012f0068 void *
x_ofs 1 int
y_ofs 47 int
seg 35 int
line 0x012f0b60 unsigned char * [0]

I've ran a trace on the code and the call stack is roughly what I would expect, is it of any use?

alld42.dll!10097efd()
[Frames below may be incorrect and/or missing, no symbols loaded for alld42.dll]
alld42.dll!100986d3()
alld42.dll!10038f93()
> anim_without_d.exe!AnimationLibraryFrame::~AnimationLibraryFrame() Line 840 + 0xf bytes C++
anim_without_d.exe!AnimationLibraryFrame::`scalar deleting destructor'() + 0x2b bytes C++
anim_without_d.exe!AnimationLibraryFrames::~AnimationLibraryFrames() Line 922 + 0x35 bytes C++
anim_without_d.exe!AnimationLibraryFrames::`scalar deleting destructor'() + 0x2b bytes C++
anim_without_d.exe!AnimationLibrary::DestroyAll() Line 1015 + 0x33 bytes C++
anim_without_d.exe!AnimationLibrary::~AnimationLibrary() Line 1008 C++
anim_without_d.exe!AnimationLibrary::`scalar deleting destructor'() + 0x2b bytes C++
anim_without_d.exe!_mangled_main() Line 224 + 0x2d bytes C++
alld42.dll!100a8950()
anim_without_d.exe!WinMain(void * hInst=0x00400000, void * hPrev=0x00000000, char * Cmd=0x001423f6, int nShow=1) Line 234 + 0x3b bytes C++
anim_without_d.exe!__tmainCRTStartup() Line 315 + 0x35 bytes C
anim_without_d.exe!WinMainCRTStartup() Line 187 C
kernel32.dll!7c816d4f()
kernel32.dll!7c8399f3()

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

ReyBrujo
Moderator
January 2001
avatar

Wait, are you absolutely sure you are first deleting the subbitmaps before deleting the parent bitmap? As per the documentation:

Quote:

BITMAP *create_sub_bitmap(BITMAP *parent, int x, y, width, height);
Creates a sub-bitmap, ie. a bitmap sharing drawing memory with a
pre-existing bitmap, but possibly with a different size and clipping
settings. When creating a sub-bitmap of the mode-X screen, the x position
must be a multiple of four. The sub-bitmap width and height can extend
beyond the right and bottom edges of the parent (they will be clipped),
but the origin point must lie within the parent region.

Returns a pointer to the created sub bitmap, or NULL if the sub bitmap
could not be created. Remember to free the sub bitmap before freeing the parent bitmap to avoid memory leaks and potential crashes accessing memory which has been freed.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Evert
Member #794
November 2000
avatar

Neil: again, have you tried to reproduce the problem with a small example programme?
If it's an Allegro problem, which is possible if you are indeed doing things correctly as you say you are, that will be nescessary to hunt down and fix the problem. If it isn't an Allegro problem it can still help you track down the problem.

Neil Walker
Member #210
April 2000
avatar

I think it is my code, and it's probably so obvious I haven't spotted it! Anyway here is my quick test code:

1 map<string,AnimationLibraryFrames*>::iterator AnimationIterator;
2 vector<AnimationLibraryFrame*>::iterator AnimationIterator2;
3 
4 for (AnimationIterator = AnimationFrames.begin(); AnimationIterator!= AnimationFrames.end(); AnimationIterator++)
5 {
6 for (AnimationIterator2 = (AnimationIterator->second)->FrameItems.begin(); AnimationIterator2!= (AnimationIterator->second)->FrameItems.end(); AnimationIterator2++)
7 {
8 if(is_sub_bitmap((*AnimationIterator2)->Image))
9 {
10 clear(screen);
11 blit((*AnimationIterator2)->Image,screen,0,0,0,0,(*AnimationIterator2)->Image->w,(*AnimationIterator2)->Image->h);
12 textprintf(screen,font,0,50,makecol(255,0,0),"%x",(*AnimationIterator2)->Image);
13 readkey();
14 destroy_bitmap((*AnimationIterator2)->Image);
15 }
16 }
17 }

Basically Frames is a map containing a vector of FrameItems. Image is a BITMAP* So the loop is simply going through each one and displaying it if it is a sub-bitmap. It displays every graphic ok, so why does it crash on the destroy_bitmap()?

Thanks.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Go to: