From 35f8570f83b79933bdd0cfff5b5f72e525546a8b Mon Sep 17 00:00:00 2001 From: Allanis Date: Tue, 27 May 2014 15:52:06 +0100 Subject: [PATCH] [Fix] Should eliminate the possibility of pilots getting destroyed by a hook while being updated. --- src/mission.c | 6 +++++- src/pilot.c | 13 +++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/mission.c b/src/mission.c index 889d706..595e62d 100644 --- a/src/mission.c +++ b/src/mission.c @@ -386,9 +386,13 @@ void missions_update(const double dt) { } } -/* Clean up a mission. */ +/** + * @brief Clean up a mission. + * @param misn Mission to clean up. + */ void mission_cleanup(Mission* misn) { int i; + if(misn->id != 0) hook_rmParent(misn->id); /* Remove existing hooks. */ diff --git a/src/pilot.c b/src/pilot.c index f831022..1adb575 100644 --- a/src/pilot.c +++ b/src/pilot.c @@ -1821,6 +1821,12 @@ void pilots_update(double dt) { for(i = 0; i < pilot_nstack; i++) { p = pilot_stack[i]; + /* Destroy pilot and go on. */ + if(pilot_isFlag(p, PILOT_DELETE)) { + pilot_destroy(p); + continue; + } + /* See if should think. */ if(p->think && !pilot_isDisabled(p)) { /* Hyperspace gets special treatment. */ @@ -1834,11 +1840,10 @@ void pilots_update(double dt) { else p->think(p); } + + /* Just update the pilot. */ if(p->update) { /* Update. */ - if(pilot_isFlag(p, PILOT_DELETE)) - pilot_destroy(p); - else - p->update(p, dt); + p->update(p, dt); } } }