From dd102c1f117e46a7a9d7d3bae0745affa4d89ac4 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sun, 10 May 2015 21:16:53 -0400 Subject: [PATCH] fix possible crash when PROT removes spark on disabled elements --- src/simulation/elements/PROT.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/simulation/elements/PROT.cpp b/src/simulation/elements/PROT.cpp index c603a33994..15604833f7 100644 --- a/src/simulation/elements/PROT.cpp +++ b/src/simulation/elements/PROT.cpp @@ -55,11 +55,17 @@ int Element_PROT::update(UPDATE_FUNC_ARGS) switch (utype) { case PT_SPRK: + { //remove active sparks - sim->part_change_type(under>>8, x, y, parts[under>>8].ctype); - parts[under>>8].life = 44 + parts[under>>8].life; - parts[under>>8].ctype = 0; + int sparked = parts[under>>8].ctype; + if (sparked >= 0 && sparked < PT_NUM && sim->elements[sparked].Enabled) + { + sim->part_change_type(under>>8, x, y, sparked); + parts[under>>8].life = 44 + parts[under>>8].life; + parts[under>>8].ctype = 0; + } break; + } case PT_DEUT: if ((-((int)sim->pv[y / CELL][x / CELL] - 4) + (parts[under>>8].life / 100)) > rand() % 200) {