Skip to content

Commit

Permalink
Fix crash when STOR is next to PIPE and has an invalid tmp value (htt…
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksonmj committed Apr 10, 2015
1 parent 72329af commit 38e21c8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/gui/game/GameController.cpp
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/simulation/Simulation.h
Expand Up @@ -132,6 +132,9 @@ class Simulation
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);
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/elements/PIPE.cpp
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/simulation/elements/STOR.cpp
Expand Up @@ -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++)
Expand Down

0 comments on commit 38e21c8

Please sign in to comment.