forked from Mirrorlandia_minetest/minetest
script: Fix add_entity returning unusable ref if object deleted in on_activate
This commit is contained in:
parent
e564bf8ead
commit
f6f6dd140f
@ -589,19 +589,19 @@ int ModApiEnvMod::l_add_entity(lua_State *L)
|
|||||||
{
|
{
|
||||||
GET_ENV_PTR;
|
GET_ENV_PTR;
|
||||||
|
|
||||||
// pos
|
|
||||||
v3f pos = checkFloatPos(L, 1);
|
v3f pos = checkFloatPos(L, 1);
|
||||||
// content
|
|
||||||
const char *name = luaL_checkstring(L, 2);
|
const char *name = luaL_checkstring(L, 2);
|
||||||
// staticdata
|
|
||||||
const char *staticdata = luaL_optstring(L, 3, "");
|
const char *staticdata = luaL_optstring(L, 3, "");
|
||||||
// Do it
|
|
||||||
ServerActiveObject *obj = new LuaEntitySAO(env, pos, name, staticdata);
|
ServerActiveObject *obj = new LuaEntitySAO(env, pos, name, staticdata);
|
||||||
int objectid = env->addActiveObject(obj);
|
int objectid = env->addActiveObject(obj);
|
||||||
// If failed to add, return nothing (reads as nil)
|
// If failed to add, return nothing (reads as nil)
|
||||||
if(objectid == 0)
|
if(objectid == 0)
|
||||||
return 0;
|
return 0;
|
||||||
// Return ObjectRef
|
|
||||||
|
// If already deleted (can happen in on_activate), return nil
|
||||||
|
if (obj->isGone())
|
||||||
|
return 0;
|
||||||
getScriptApiBase(L)->objectrefGetOrCreate(L, obj);
|
getScriptApiBase(L)->objectrefGetOrCreate(L, obj);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user