summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_env.cpp
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2020-04-26 20:29:16 +0200
committerLoïc Blot <nerzhul@users.noreply.github.com>2020-04-27 06:58:34 +0200
commitf6f6dd140f14a40a43a63a1ba3eccc66fd56d514 (patch)
tree3578bb56caf87356aef647e7823c24d13e573475 /src/script/lua_api/l_env.cpp
parente564bf8eadb5aee7a90b2184b03316917c580aed (diff)
downloadminetest-f6f6dd140f14a40a43a63a1ba3eccc66fd56d514.tar.gz
minetest-f6f6dd140f14a40a43a63a1ba3eccc66fd56d514.tar.bz2
minetest-f6f6dd140f14a40a43a63a1ba3eccc66fd56d514.zip
script: Fix add_entity returning unusable ref if object deleted in on_activate
Diffstat (limited to 'src/script/lua_api/l_env.cpp')
-rw-r--r--src/script/lua_api/l_env.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index 3fb58b8c8..cabca124d 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -589,19 +589,19 @@ int ModApiEnvMod::l_add_entity(lua_State *L)
{
GET_ENV_PTR;
- // pos
v3f pos = checkFloatPos(L, 1);
- // content
const char *name = luaL_checkstring(L, 2);
- // staticdata
const char *staticdata = luaL_optstring(L, 3, "");
- // Do it
+
ServerActiveObject *obj = new LuaEntitySAO(env, pos, name, staticdata);
int objectid = env->addActiveObject(obj);
// If failed to add, return nothing (reads as nil)
if(objectid == 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);
return 1;
}