From 7a844f51ff7673aa49aee0f04517235c9a4da84a Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sat, 14 Apr 2012 19:12:08 +0100 Subject: [PATCH] Fix crash when flood fill deleting life --- src/powder.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/powder.c b/src/powder.c index ceab90e16..6dc06554d 100644 --- a/src/powder.c +++ b/src/powder.c @@ -592,11 +592,20 @@ void 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) //This shouldn't happen anymore, but it's here just in case return; - x = (int)(parts[i].x+0.5f); - y = (int)(parts[i].y+0.5f); if (parts[i].type == PT_STKM) { player.spwn = 0; @@ -622,12 +631,6 @@ void 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;