Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Game failure at return 0; at the end of the main loop

This thread is locked; no one can reply to it. rss feed Print
Game failure at return 0; at the end of the main loop
Miles Lombardi
Member #5,876
May 2005

My game is pointer erroring at the return 0; at the end of the main loop.
The code i just added destroys some BITMAPs (as far as I can tell they are not used after this).

But why would it pointer error there?

X-G
Member #856
December 2000
avatar

Because you're a bad, bad person and are not showing us any damn code.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Miles Lombardi
Member #5,876
May 2005

Well i wouldn't have a clue waht to show you:

main:

int main() {
  init();

  while (run) loop();

  deinit();
  return 0;
}

That's a bit useless.

You see the problem occurs at return 0; So where am i supposed to show you?

loop:

void loop(){
     if (key[KEY_ESC]) game_exit();
     if (room == cRoom->id){
        cRoom->constructor();
        while (room == cRoom->id){allrooms(); cRoom->exec(); }
        cRoom->destructor();
     }
     else cRoom = rooms[room - 1];
}

The current constructor exec and destructor:

1void rm_title_Start(){
2 install_int (rm_title_callback, 750);
3 title_press_start = load_bitmap("graphics/title/press_start.png", NULL);
4 title_background = load_bitmap("graphics/title/title.png", NULL);
5}
6 
7 
8 
9void rm_title_Loop(){
10 
11 if (draw_bg){
12 draw_bg = 0;
13 draw_sprite(sbuffer, title_background, 0, 0);
14 }
15 if (draw_start){
16 draw_start = 0;
17 draw_sprite(sbuffer, title_press_start, 120-title_press_start->w/2,125);
18 }
19 rest(30);
20}
21 
22 
23void rm_title_End(){
24 remove_int(rm_title_callback);
25 destroy_bitmap (title_press_start);
26 destroy_bitmap (title_background);
27}

It was those destroy_bitmaps() that I added as I realised I'd forgotten to do that.
I also moved the load_bitmap s from the load_bitmaps() function into there, so it's easier to see what I'm working with.

Hrvoje Ban
Member #4,537
April 2004
avatar

Make sure that you're not destroying any bitmaps in global objects destructors.

ReyBrujo
Moderator
January 2001
avatar

Are you destroying all the bitmaps, like sbuffer?

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

Evert
Member #794
November 2000
avatar

Are you setting free'ed pointers to NULL?

Miles Lombardi
Member #5,876
May 2005

It's this:
Make sure that you're not destroying any bitmaps in global objects destructors.
I haven't checked it yet, but I just realised that the destructor function is run twice. The second time in the return 0; This is because it's run inside a class destructor.

Go to: