Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Bitmap array

This thread is locked; no one can reply to it. rss feed Print
Bitmap array
Ceagon Xylas
Member #5,495
February 2005
avatar

Now I know 24,467 people have asked how to do this or have been shown how to do this -- but when I finally can't remember how to, the Allegro search completely fails me. How on earth do you load into a BITMAP* array?!

BITMAP *sprite_g[255];

main() {
  sprite_g[0]=load_pcx("file.pcx",NULL);
  sprite_g[1]=load_pcx("file.pcx",NULL);

  draw_sprite(buffer,sprite_g[0],0,0);
  draw_sprite(buffer,sprite_g[1],320,0);

  for(int i=0; i<255; i++) destroy_bitmap(sprite_g<i>);
}

This is crashing for me every time. Checked my file paths, they're correct. I can get this to work:

  for(int i=0; i<255; i++) {
    sprite_g<i>=create_bitmap(20,20);
    clear_to_color(sprite_g<i>,makecol(255,255,255));
  }
  draw_sprite(buffer,sprite_g[0],0,0);

But whenever I load the file into the array it's not workin'.

miran
Member #2,407
June 2002

1. Initialize bitmaps to 0 before loading.
2. Check if 0 before drawing.
3. Check if 0 before destroying.
4. Set to 0 after destroying.

Note: #3 may not be necessary.

--
sig used to be here

ReyBrujo
Moderator
January 2001
avatar

If your code, you load two bitmaps, all the other positions have trash since they aren't initialized. At the end of the program you try to destroy 256 bitmaps, but only two have been allocated. Probably when i = 2 destroy_bitmap crashes.

(Plus miran's suggestions, of course)

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

Ceagon Xylas
Member #5,495
February 2005
avatar

It's crashing on the draw_sprite() function almost certainly. The reason I say that is because it runs fine until I press 'a' in this program:

//declare bitmaps

main() {
  while(!end_program) {
    if(key[KEY_A]) draw_sprite(buffer,sprite_g[0],0,0);
    //blit the buffer
  }
  //destroy_bitmap for loop
}

I'll try what you said, miran.

[edit]
Yay! I solved it! Thanks guys! =P
Basically, yeah, just had to initialize the entire array.

miran
Member #2,407
June 2002

Yay!

--
sig used to be here

A J
Member #3,025
December 2002
avatar

Quote:

It's crashing on the draw_sprite() function almost certainly.

ALMOST What do you mean almost, dont you know ?

Do you know how to use a debugger ?

___________________________
The more you talk, the more AJ is right. - ML

CGamesPlay
Member #2,559
July 2002
avatar

More importantly, initialize allegro!

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Go to: