mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-29 19:00:33 +02:00
Fix cryptic level 0 Lua error built-in elements sometimes produce
If the built-in update function is allowed to run, it can change the particle's type. The code path assumes that there is a Lua update function to call on the particle, but this type change may break this assumption and cause the code to call the update function of an element that doesn't even have one, producing a weird error message with no line number.
This commit is contained in:
@@ -2948,8 +2948,6 @@ int LuaScriptInterface::elements_allocate(lua_State * l)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int luaUpdateWrapper(UPDATE_FUNC_ARGS)
|
static int luaUpdateWrapper(UPDATE_FUNC_ARGS)
|
||||||
{
|
|
||||||
if (lua_el_func[parts[i].type])
|
|
||||||
{
|
{
|
||||||
auto *builtinUpdate = GetElements()[parts[i].type].Update;
|
auto *builtinUpdate = GetElements()[parts[i].type].Update;
|
||||||
if (builtinUpdate && lua_el_mode[parts[i].type] == 1)
|
if (builtinUpdate && lua_el_mode[parts[i].type] == 1)
|
||||||
@@ -2959,6 +2957,8 @@ static int luaUpdateWrapper(UPDATE_FUNC_ARGS)
|
|||||||
x = (int)(parts[i].x+0.5f);
|
x = (int)(parts[i].x+0.5f);
|
||||||
y = (int)(parts[i].y+0.5f);
|
y = (int)(parts[i].y+0.5f);
|
||||||
}
|
}
|
||||||
|
if (lua_el_func[parts[i].type])
|
||||||
|
{
|
||||||
int retval = 0, callret;
|
int retval = 0, callret;
|
||||||
lua_rawgeti(luacon_ci->l, LUA_REGISTRYINDEX, lua_el_func[parts[i].type]);
|
lua_rawgeti(luacon_ci->l, LUA_REGISTRYINDEX, lua_el_func[parts[i].type]);
|
||||||
lua_pushinteger(luacon_ci->l, i);
|
lua_pushinteger(luacon_ci->l, i);
|
||||||
@@ -2979,6 +2979,7 @@ static int luaUpdateWrapper(UPDATE_FUNC_ARGS)
|
|||||||
}
|
}
|
||||||
x = (int)(parts[i].x+0.5f);
|
x = (int)(parts[i].x+0.5f);
|
||||||
y = (int)(parts[i].y+0.5f);
|
y = (int)(parts[i].y+0.5f);
|
||||||
|
}
|
||||||
if (builtinUpdate && lua_el_mode[parts[i].type] == 3)
|
if (builtinUpdate && lua_el_mode[parts[i].type] == 3)
|
||||||
{
|
{
|
||||||
if (builtinUpdate(UPDATE_FUNC_SUBCALL_ARGS))
|
if (builtinUpdate(UPDATE_FUNC_SUBCALL_ARGS))
|
||||||
@@ -2986,7 +2987,6 @@ static int luaUpdateWrapper(UPDATE_FUNC_ARGS)
|
|||||||
x = (int)(parts[i].x+0.5f);
|
x = (int)(parts[i].x+0.5f);
|
||||||
y = (int)(parts[i].y+0.5f);
|
y = (int)(parts[i].y+0.5f);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user