Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » blit crash!

This thread is locked; no one can reply to it. rss feed Print
blit crash!
khristina yer
Member #5,795
May 2005
avatar

I have this piece of code:

            blit(graphicpack.background[0],drawto.drawon(),
            0,0,0,0,800,600);//draw demon background.

it crashes at this point.
graphicpack.background[0] is loaded up in memory. the bitmap returned by drawto.drawon() is allocated in video memory space.

what could I be doing wrong to cause allegro to crash?

miran
Member #2,407
June 2002

Post more background information. More code, circumstances in which it happens, etc...

--
sig used to be here

khristina yer
Member #5,795
May 2005
avatar

this is where graphicpack.background[0] gets loaded.
background[go]=load_bitmap(filename,NULL);
this is what drawto.drawon() returns

BITMAP* DrawEngine::drawon()
{
    return drawimage[which];
}

This is where drawimage[which] gets created.

    drawimage[0]=create_video_bitmap(x,y);
    drawimage[1]=create_video_bitmap(x,y);

of course I did do error checking so I know they are there.

I really don't know what other details I can post, without handing out the src code.

it crashes at the blit. It sets the video mode, loads the graphics, reserves video memory, and then when I try to do the blit, it will crash.

would blitting from a memory bitmap to a video memory bitmap cause this problem?

miran
Member #2,407
June 2002

Quote:

would blitting from a memory bitmap to a video memory bitmap cause this problem?

I don't think so. Blit crashing usually indicates that there's something wrong with at least one of the bitmaps in question.

What are the values of x and y in create_video_bitmap()? Do you set the colour depth after setting the gfx mode? Do you load the background and/or create the video pages before setting the gfx mode? Does the same happen if you use memory back buffer?

--
sig used to be here

khristina yer
Member #5,795
May 2005
avatar

Quote:

What are the values of x and y in create_video_bitmap()?

800 x 600 y in this test run.

Quote:

Do you set the colour depth before setting the gfx mode?

yes I set it to 16

Quote:

Do you load the background and create the video pages after setting the gfx mode?

yes it sets the resolution and then I load the background and create the video pages.

I don't know whats wrong.

[edit]
I blitted from the screen to the video buffer. And that did not crash. So I'm guessing something is wrong with my picture. But what could that be?

Also I saved grahpicpack.background[0] to a file, and it looked fine.

miran
Member #2,407
June 2002

Try to create a minimal example that shows the problem and post the code (all of it, with main() and everything). Should be around 20 lines.

--
sig used to be here

khristina yer
Member #5,795
May 2005
avatar

1#include <allegro.h>
2 
3int main(int argv,char* argc[])
4{
5 allegro_init();
6 install_timer();
7
8 BITMAP* background;
9 BITMAP* buffer[2];
10
11 set_color_depth(16);
12 set_gfx_mode(GFX_AUTODETECT_WINDOWED,800,600,0,0);
13
14 background=load_bmp("background.bmp",NULL);
15 buffer[0]=create_video_bitmap(800,600);
16 buffer[1]=create_video_bitmap(800,600);
17 int which=0;
18
19 while(TRUE)
20 {
21 blit(background,buffer[which],
22 0,0,0,0,800,600);//draw demon background.
23 show_video_bitmap(buffer[which]);
24 if(which==0){which=1;}else {which=0;}
25 }
26 
27}
28
29
30 END_OF_MAIN();

I compiled and tested this code. It did not crash. It did just what I wanted it to do.

umperio
Member #3,474
April 2003
avatar

If your code is not secret, nor very long maybe you could try posting it, so we can give a debug at it.

I know it's not the problem, but I prefer the following:

which = 1 - which;

which is cleaner.

khristina yer
Member #5,795
May 2005
avatar

The code is very long, but I'll make a attachment.

Please be gentle with the criticism.

miran
Member #2,407
June 2002

EDIT: Posted before the last post :-X

That only shows the problem is not with blitting the background to a video bitmap but somewhere else. Try to create a minimal example that shows the problem and post the code.

---------
EDIT:
I didn't compile the code ::), but I noticed that background0.bmp isn't an 800x600 bitmap. It's 800x54...

--
sig used to be here

khristina yer
Member #5,795
May 2005
avatar

Quote:

I noticed that background0.bmp isn't an 800x600 bitmap. It's 800x54...

Thats strange! All of my programs report it as 800x600. I used gimp to make it. Do you think gimp has it messed up somehow?

miran
Member #2,407
June 2002

Sorry, my mistake. I'm having problems with my image viewer program... :-X

--
sig used to be here

umperio
Member #3,474
April 2003
avatar

At first, the problem seems to be related to graphicpack.background[0] not being loaded correctly, in fact blitting a loaded bitmap to drawto.drawon() works perfectly, but saving graphicpack.background[0], gave an image which cannot be open. I wonder how you managed to save it.
Anyway that's not the only problem since removing the blitting code still crashes the whole thing.

khristina yer
Member #5,795
May 2005
avatar

The next crash would probably be another blit.

Well I can't find out whats wrong. I've checked the address of background it self, It looks like it loaded. The background isn't loading correctly. But why is everthing reporting that its fine? Is it getting lost somewhere? I'm going to try and blit the freshly loaded image before that function ends.

[REPORT]
Ok it blitted the freshly loaded image. And it worked fine. I checked the address in that spot with the address on the outside where it crashes. They have the same address, So what could cause it to be unloaded?

Go to: