diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 792120643..8a8f1dfdb 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -1476,7 +1476,7 @@ bool GameController::IsValidElement(int type) { if(gameModel && gameModel->GetSimulation()) { - return (type > 0 && type < PT_NUM && gameModel->GetSimulation()->elements[type].Enabled); + return (type && gameModel->GetSimulation()->IsValidElement(type)); } else return false; diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index 43e34f9a0..dc4cca041 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -132,6 +132,9 @@ public: int eval_move(int pt, int nx, int ny, unsigned *rr); void init_can_move(); bool IsWallBlocking(int x, int y, int type); + bool IsValidElement(int type) { + return (type >= 0 && type < PT_NUM && elements[type].Enabled); + } void create_cherenkov_photon(int pp); void create_gain_photon(int pp); void kill_part(int i); diff --git a/src/simulation/elements/PIPE.cpp b/src/simulation/elements/PIPE.cpp index 01a189b54..86f15d60e 100644 --- a/src/simulation/elements/PIPE.cpp +++ b/src/simulation/elements/PIPE.cpp @@ -210,7 +210,7 @@ int Element_PIPE::update(UPDATE_FUNC_ARGS) transfer_part_to_pipe(parts+(r>>8), parts+i); sim->kill_part(r>>8); } - else if ((parts[i].tmp&0xFF) == 0 && (r&0xFF)==PT_STOR && parts[r>>8].tmp && (sim->elements[parts[r>>8].tmp].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))) + else if ((parts[i].tmp&0xFF) == 0 && (r&0xFF)==PT_STOR && parts[r>>8].tmp>0 && sim->IsValidElement(parts[r>>8].tmp) && (sim->elements[parts[r>>8].tmp].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))) { // STOR stores properties in the same places as PIPE does transfer_pipe_to_pipe(parts+(r>>8), parts+i); diff --git a/src/simulation/elements/STOR.cpp b/src/simulation/elements/STOR.cpp index 348297c28..85a0193b1 100644 --- a/src/simulation/elements/STOR.cpp +++ b/src/simulation/elements/STOR.cpp @@ -50,6 +50,8 @@ Element_STOR::Element_STOR() int Element_STOR::update(UPDATE_FUNC_ARGS) { int r, rx, ry, np, rx1, ry1; + if (!sim->IsValidElement(parts[i].tmp)) + parts[i].tmp = 0; if(parts[i].life && !parts[i].tmp) parts[i].life--; for (rx=-2; rx<3; rx++)