From 70a815a8c70d403e4618e72b7fee3bac0937c1a7 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sat, 29 Nov 2014 00:30:05 -0500 Subject: [PATCH] fix crash when PIPE finds PRTI with an invalid channel --- src/simulation/elements/PIPE.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/simulation/elements/PIPE.cpp b/src/simulation/elements/PIPE.cpp index 3e24c1b76..e8c82347a 100644 --- a/src/simulation/elements/PIPE.cpp +++ b/src/simulation/elements/PIPE.cpp @@ -454,11 +454,15 @@ void Element_PIPE::pushParticle(Simulation * sim, int i, int count, int original } else if ((r&0xFF) == PT_PRTI) //Pass particles into PRTI for a pipe speed increase { - int nnx; - for (nnx=0; nnx<80; nnx++) - if (!sim->portalp[sim->parts[r>>8].tmp][count][nnx].type) + int portaltmp = sim->parts[r>>8].tmp; + if (portaltmp >= CHANNELS) + portaltmp = CHANNELS-1; + else if (portaltmp < 0) + portaltmp = 0; + for (int nnx = 0; nnx < 80; nnx++) + if (!sim->portalp[portaltmp][count][nnx].type) { - transfer_pipe_to_part(sim, sim->parts+i, &(sim->portalp[sim->parts[r>>8].tmp][count][nnx])); + transfer_pipe_to_part(sim, sim->parts+i, &(sim->portalp[portaltmp][count][nnx])); count++; break; } @@ -480,11 +484,15 @@ void Element_PIPE::pushParticle(Simulation * sim, int i, int count, int original } else if ((r&0xFF) == PT_PRTI) //Pass particles into PRTI for a pipe speed increase { - int nnx; - for (nnx=0; nnx<80; nnx++) - if (!sim->portalp[sim->parts[r>>8].tmp][count][nnx].type) + int portaltmp = sim->parts[r>>8].tmp; + if (portaltmp >= CHANNELS) + portaltmp = CHANNELS-1; + else if (portaltmp < 0) + portaltmp = 0; + for (int nnx = 0; nnx < 80; nnx++) + if (!sim->portalp[portaltmp][count][nnx].type) { - transfer_pipe_to_part(sim, sim->parts+i, &(sim->portalp[sim->parts[r>>8].tmp][count][nnx])); + transfer_pipe_to_part(sim, sim->parts+i, &(sim->portalp[portaltmp][count][nnx])); count++; break; }