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:
Tamás Bálint Misius 2022-03-31 16:46:24 +02:00
parent b2ddb39b42
commit 254b4a642a
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2

View File

@ -2949,16 +2949,16 @@ int LuaScriptInterface::elements_allocate(lua_State * l)
static int luaUpdateWrapper(UPDATE_FUNC_ARGS)
{
auto *builtinUpdate = GetElements()[parts[i].type].Update;
if (builtinUpdate && lua_el_mode[parts[i].type] == 1)
{
if (builtinUpdate(UPDATE_FUNC_SUBCALL_ARGS))
return 1;
x = (int)(parts[i].x+0.5f);
y = (int)(parts[i].y+0.5f);
}
if (lua_el_func[parts[i].type])
{
auto *builtinUpdate = GetElements()[parts[i].type].Update;
if (builtinUpdate && lua_el_mode[parts[i].type] == 1)
{
if (builtinUpdate(UPDATE_FUNC_SUBCALL_ARGS))
return 1;
x = (int)(parts[i].x+0.5f);
y = (int)(parts[i].y+0.5f);
}
int retval = 0, callret;
lua_rawgeti(luacon_ci->l, LUA_REGISTRYINDEX, lua_el_func[parts[i].type]);
lua_pushinteger(luacon_ci->l, i);
@ -2979,13 +2979,13 @@ static int luaUpdateWrapper(UPDATE_FUNC_ARGS)
}
x = (int)(parts[i].x+0.5f);
y = (int)(parts[i].y+0.5f);
if (builtinUpdate && lua_el_mode[parts[i].type] == 3)
{
if (builtinUpdate(UPDATE_FUNC_SUBCALL_ARGS))
return 1;
x = (int)(parts[i].x+0.5f);
y = (int)(parts[i].y+0.5f);
}
}
if (builtinUpdate && lua_el_mode[parts[i].type] == 3)
{
if (builtinUpdate(UPDATE_FUNC_SUBCALL_ARGS))
return 1;
x = (int)(parts[i].x+0.5f);
y = (int)(parts[i].y+0.5f);
}
return 0;
}