Skip to content

Commit

Permalink
script: Fix add_entity returning unusable ref if object deleted in on…
Browse files Browse the repository at this point in the history
…_activate
  • Loading branch information
sfan5 authored and nerzhul committed Apr 27, 2020
1 parent e564bf8 commit f6f6dd1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/script/lua_api/l_env.cpp
Expand Up @@ -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;
}
Expand Down

0 comments on commit f6f6dd1

Please sign in to comment.