Meh, its just to short hand it, works everywhere else.
So I switched it to it++ rather than ++it, made no difference. I'm going through a list of objects defined as BODY_DATA(celestial bodies), a custom class. I've expanded it with -gdb and -g3, but it still won't expand the macro, maybe I'm missing something. However, the macro itself works in 45 other places and never has an issue. Infact, this specific piece of code is called repeatedly, and only fails in one circumstance.
Here is my gdb bt infoProgram received signal SIGSEGV, Segmentation fault.
0x0808a8df in std::list<BODY_DATA*, std::allocator<BODY_DATA*> >::end (this=0x28) at stl_list.h:583
583 end() { return _M_node; }
(gdb) bt
#0 0x0808a8df in std::list<BODY_DATA*, std::allocator<BODY_DATA*> >::end (this=0x28) at stl_list.h:583
#1 0x081de310 in move_ships () at space.c:312
#2 0x0822fdf6 in update_handler () at update.c:3158
#3 0x0810d5d7 in game_loop () at comm.c:865
#4 0x0810c5f0 in main (argc=2, argv=0xbffffd04) at comm.c:353
(gdb) frame 0
#0 0x0808a8df in std::list<BODY_DATA*, std::allocator<BODY_DATA*> >::end (this=0x28) at stl_list.h:583
583 end() { return _M_node; }
(gdb) print _M_node
Cannot access memory at address 0x28
The corresponding valgrind info==15987== Invalid read of size 4
==15987== at 0x81716B6: move_ships() (stl_list.h:155)
==15987== by 0x81AF84E: update_handler() (update.c:3158)
==15987== by 0x80D06E1: game_loop() (comm.c:865)
==15987== by 0x80CFC3B: main (comm.c:353)
==15987== Address 0x28 is not stack'd, malloc'd or (recently) free'd
==15987== TRANSLATE: 0x1BA6EEA0 redirected to 0x1B8FEC0F
And the code itselfline 312---> FOR_EACH_LIST(BODY_LIST, ship->starsystem->bodies, body)
{
int distance = 0;
if (ship->currspeed <= 0)
continue;
distance = body->distance(ship);
if ((distance < body->gravity() / 10)
&& body->type() == STAR_BODY && distance > 0)
{
echo_to_cockpit(AT_BLOOD + AT_BLINK, ship,
"You fly directly into the sun.");
snprintf(buf, MSL,
"%s flys directly into %s!",
ship->name, body->name());
echo_to_system(AT_ORANGE, ship, buf, NULL);
destroy_ship(ship, NULL);
continue;
}
if (distance < body->gravity()
&& (body->type() == PLANET_BODY
|| body->type() == MOON_BODY))
{
snprintf(buf, MSL, "You begin orbitting %s.",
body->name());
echo_to_cockpit(AT_YELLOW, ship, buf);
snprintf(buf, MSL, "%s begins orbiting %s.",
ship->name, body->name());
echo_to_system(AT_ORANGE, ship, buf, NULL);
ship->currspeed = 0;
continue;
}
}
It only happens after the ship has gone through the section with destroy_ship, so I'm assuming something in there is killing ships, but I can make repeated calls to it outside of this loop with no problems at all at, no leaks with it anywhere.
Maybe someone can see something I can't, cause this is really bugging me. |