Game failure at return 0; at the end of the main loop
Miles Lombardi

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

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

Miles Lombardi

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

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

ReyBrujo

Are you destroying all the bitmaps, like sbuffer?

Evert

Are you setting free'ed pointers to NULL?

Miles Lombardi

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.

Thread #567657. Printed from Allegro.cc