safeguard FloodParts and kill_part (#717)

This commit is contained in:
QuanTech0 2020-05-11 10:20:01 -04:00 committed by GitHub
parent 49963980e6
commit dda7747688
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -1355,6 +1355,10 @@ int LuaScriptInterface::simulation_floodParts(lua_State * l)
int c = luaL_optint(l,3,luacon_model->GetActiveTool(0)->GetToolID());
int cm = luaL_optint(l,4,-1);
int flags = luaL_optint(l,5,luacon_sim->replaceModeFlags);
if (x < CELL || x >= XRES-CELL || y < CELL || y >= YRES-CELL)
return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
int ret = luacon_sim->FloodParts(x, y, c, cm, flags);
lua_pushinteger(l, ret);
return 1;

View File

@ -1900,6 +1900,7 @@ int Simulation::FloodParts(int x, int y, int fullc, int cm, int flags)
return 1;
else if (x < 0 || x >= XRES || y < 0 || y >= YRES)
return 1;
if (c == 0)
{
cm = TYP(pmap[y][x]);
@ -1918,6 +1919,7 @@ int Simulation::FloodParts(int x, int y, int fullc, int cm, int flags)
else
cm = 0;
}
if (c != 0 && IsWallBlocking(x, y, c))
return 1;
@ -3036,6 +3038,9 @@ int Simulation::get_normal_interp(int pt, float x0, float y0, float dx, float dy
void Simulation::kill_part(int i)//kills particle number i
{
if (i < 0 || i >= NPART)
return;
int x = (int)(parts[i].x + 0.5f);
int y = (int)(parts[i].y + 0.5f);