Fix crash when STOR is next to PIPE and has an invalid tmp value (http://tpt.io/~1768004)

This commit is contained in:
jacksonmj 2015-04-10 14:23:58 +01:00
parent 72329af09d
commit 38e21c8236
4 changed files with 7 additions and 2 deletions

View File

@ -1476,7 +1476,7 @@ bool GameController::IsValidElement(int type)
{ {
if(gameModel && gameModel->GetSimulation()) if(gameModel && gameModel->GetSimulation())
{ {
return (type > 0 && type < PT_NUM && gameModel->GetSimulation()->elements[type].Enabled); return (type && gameModel->GetSimulation()->IsValidElement(type));
} }
else else
return false; return false;

View File

@ -132,6 +132,9 @@ public:
int eval_move(int pt, int nx, int ny, unsigned *rr); int eval_move(int pt, int nx, int ny, unsigned *rr);
void init_can_move(); void init_can_move();
bool IsWallBlocking(int x, int y, int type); 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_cherenkov_photon(int pp);
void create_gain_photon(int pp); void create_gain_photon(int pp);
void kill_part(int i); void kill_part(int i);

View File

@ -210,7 +210,7 @@ int Element_PIPE::update(UPDATE_FUNC_ARGS)
transfer_part_to_pipe(parts+(r>>8), parts+i); transfer_part_to_pipe(parts+(r>>8), parts+i);
sim->kill_part(r>>8); 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 // STOR stores properties in the same places as PIPE does
transfer_pipe_to_pipe(parts+(r>>8), parts+i); transfer_pipe_to_pipe(parts+(r>>8), parts+i);

View File

@ -50,6 +50,8 @@ Element_STOR::Element_STOR()
int Element_STOR::update(UPDATE_FUNC_ARGS) int Element_STOR::update(UPDATE_FUNC_ARGS)
{ {
int r, rx, ry, np, rx1, ry1; int r, rx, ry, np, rx1, ry1;
if (!sim->IsValidElement(parts[i].tmp))
parts[i].tmp = 0;
if(parts[i].life && !parts[i].tmp) if(parts[i].life && !parts[i].tmp)
parts[i].life--; parts[i].life--;
for (rx=-2; rx<3; rx++) for (rx=-2; rx<3; rx++)