From 39c7a4ecd5df76c2d17765659400e9175322e371 Mon Sep 17 00:00:00 2001 From: Allanis Date: Tue, 26 Nov 2013 16:03:17 +0000 Subject: [PATCH] [Fix?] Finally think I fixed it. The dialogue was being called when the weapons were being updated (hook on death) and the main_loop was being handled before the loop was destroyed. So another iteration of weapon_update was being run in the middle of the first one, causing a double weapon_destroy to be triggered. Moving the main_loop() in secondary_loop to the top so that the loop condition is run right after the event handling will solve this as an iteration won't be run in between dialogues. --- src/dialogue.c | 4 +++- src/weapon.c | 31 ++++++++++++++++--------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/dialogue.c b/src/dialogue.c index bdfaa73..6d5962c 100644 --- a/src/dialogue.c +++ b/src/dialogue.c @@ -286,6 +286,9 @@ static int toolkit_loop(void) { loop_done = 0; while(!loop_done && toolkit) { + /* Loop first so exit condition is checked before next iteration. */ + main_loop(); + while(SDL_PollEvent(&event)) { /* Event loop. */ if(event.type == SDL_QUIT) { /* Pass quit event to main engine. */ loop_done = 1; @@ -294,7 +297,6 @@ static int toolkit_loop(void) { } input_handle(&event); /* Handles all the events and player keybinds. */ } - main_loop(); } return 0; diff --git a/src/weapon.c b/src/weapon.c index bda32b5..e9deb97 100644 --- a/src/weapon.c +++ b/src/weapon.c @@ -325,40 +325,41 @@ static void weapons_updateLayer(const double dt, const WeaponLayer layer) { i = 0; while(i < *nlayer) { w = wlayer[i]; - switch(wlayer[i]->outfit->type) { + switch(w->outfit->type) { /* Most missiles behave the same. */ case OUTFIT_TYPE_MISSILE_SEEK_AMMO: case OUTFIT_TYPE_MISSILE_SEEK_SMART_AMMO: case OUTFIT_TYPE_MISSILE_SWARM_AMMO: case OUTFIT_TYPE_MISSILE_SWARM_SMART_AMMO: - if(wlayer[i]->lockon > 0.) /* Decrement lockon. */ - wlayer[i]->lockon -= dt; + if(w->lockon > 0.) /* Decrement lockon. */ + w->lockon -= dt; /* Purpose fallthrough. */ /* Bolts too. */ case OUTFIT_TYPE_BOLT: case OUTFIT_TYPE_TURRET_BOLT: case OUTFIT_TYPE_MISSILE_DUMB_AMMO: /* Dumb missiles are like bolts. */ - wlayer[i]->timer -= dt; - if(wlayer[i]->timer < 0.) { - weapon_destroy(wlayer[i], layer); + w->timer -= dt; + if(w->timer < 0.) { + weapon_destroy(w, layer); break; } break; /* Beam weapons handled apart. */ case OUTFIT_TYPE_BEAM: case OUTFIT_TYPE_TURRET_BEAM: - wlayer[i]->timer -= dt; - if(wlayer[i]->timer < 0.) { - weapon_destroy(wlayer[i],layer); + w->timer -= dt; + if(w->timer < 0.) { + weapon_destroy(w, layer); break; } - wlayer[i]->lockon -= dt; - if(wlayer[i]->lockon < 0.) { - if(wlayer[i]->lockon < -1.) - wlayer[i]->lockon = 0.100; + /* We use the lockon to tell when we have to create explosions. */ + w->lockon -= dt; + if(w->lockon < 0.) { + if(w->lockon < -1.) + w->lockon = 0.100; else - wlayer[i]->lockon = -1.; + w->lockon = -1.; } break; default: @@ -373,7 +374,7 @@ static void weapons_updateLayer(const double dt, const WeaponLayer layer) { /* Only increment if weapon wasn't deleted. */ if(w == wlayer[i]) { - weapon_update(wlayer[i], dt, layer); + weapon_update(w, dt, layer); if((i < *nlayer) && (w == wlayer[i])) i++; }