From 2140beb9ccf0e414f8fa92328333d062e5e10942 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Mon, 25 Aug 2014 19:05:32 -0400 Subject: [PATCH] make sure soap doesn't crash when messed with in the console --- src/graphics/Renderer.cpp | 2 +- src/simulation/elements/SOAP.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index 418e4ba86..5715a09c0 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -1365,7 +1365,7 @@ void Renderer::render_parts() { if (t==PT_SOAP) { - if ((parts[i].ctype&7) == 7) + if ((parts[i].ctype&7) == 7 && parts[i].tmp >= 0 && parts[i].tmp < NPART && parts[i].tmp2 >= 0 && parts[i].tmp2 < NPART) draw_line(nx, ny, (int)(parts[parts[i].tmp].x+0.5f), (int)(parts[parts[i].tmp].y+0.5f), colr, colg, colb, cola); } } diff --git a/src/simulation/elements/SOAP.cpp b/src/simulation/elements/SOAP.cpp index e18ad284a..c88314302 100644 --- a/src/simulation/elements/SOAP.cpp +++ b/src/simulation/elements/SOAP.cpp @@ -104,6 +104,11 @@ int Element_SOAP::update(UPDATE_FUNC_ARGS) { if (parts[i].temp>FREEZING) { + if (parts[i].tmp < 0 || parts[i].tmp >= NPART || parts[i].tmp2 < 0 || parts[i].tmp2 >= NPART) + { + parts[i].tmp = parts[i].tmp2 = parts[i].ctype = 0; + return 0; + } if (parts[i].life<=0) { //if only connected on one side