diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 017925acd..fdc94ab80 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -1703,13 +1703,22 @@ void Simulation::kill_part(int i)//kills particle number i { int x, y; + // Remove from pmap even if type==0, otherwise infinite recursion occurs when flood fill deleting + // a particle which sets type to 0 without calling kill_part (such as LIFE) + x = (int)(parts[i].x+0.5f); + y = (int)(parts[i].y+0.5f); + if (x>=0 && y>=0 && x>8)==i) + pmap[y][x] = 0; + else if ((photons[y][x]>>8)==i) + photons[y][x] = 0; + } + if (parts[i].type == PT_NONE) return; if(elementCount[parts[i].type] && parts[i].type) elementCount[parts[i].type]--; - x = (int)(parts[i].x+0.5f); - y = (int)(parts[i].y+0.5f); if (parts[i].type == PT_STKM) { player.spwn = 0; @@ -1727,12 +1736,6 @@ void Simulation::kill_part(int i)//kills particle number i { detach(i); } - if (x>=0 && y>=0 && x>8)==i) - pmap[y][x] = 0; - else if ((photons[y][x]>>8)==i) - photons[y][x] = 0; - } parts[i].type = PT_NONE; parts[i].life = pfree;