diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 42395717f..2a8b8a64e 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -140,8 +140,9 @@ int ObjectRef::l_remove(lua_State *L) UNORDERED_SET child_ids = co->getAttachmentChildIds(); UNORDERED_SET::iterator it; for (it = child_ids.begin(); it != child_ids.end(); ++it) { - ServerActiveObject *child = env->getActiveObject(*it); - child->setAttachment(0, "", v3f(0, 0, 0), v3f(0, 0, 0)); + // Child can be NULL if it was deleted earlier + if (ServerActiveObject *child = env->getActiveObject(*it)) + child->setAttachment(0, "", v3f(0, 0, 0), v3f(0, 0, 0)); } verbosestream<<"ObjectRef::l_remove(): id="<getId()<