[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.

This commit is contained in:
Allanis 2013-11-26 16:03:17 +00:00
parent 96587aac90
commit 39c7a4ecd5
2 changed files with 19 additions and 16 deletions

View File

@ -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;

View File

@ -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++;
}