aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRogier <rogier777@gmail.com>2016-11-06 16:18:29 +0100
committerNer'zhul <nerzhul@users.noreply.github.com>2016-11-13 10:10:28 +0100
commit1980d9ea31e969c5b604f6ee01693cbcfc2c795a (patch)
treebabe0e607937d8decffcd8451d04b912e8145b5c /src
parente4031156f13d062b03960e7ef1c9221f749f884b (diff)
downloadminetest-1980d9ea31e969c5b604f6ee01693cbcfc2c795a.tar.gz
minetest-1980d9ea31e969c5b604f6ee01693cbcfc2c795a.tar.bz2
minetest-1980d9ea31e969c5b604f6ee01693cbcfc2c795a.zip
Fix crash when attached object no longer exists
Active objects that are attached to other objects are not safe from deletion. As a result, the parent object may have a reference to an id of a child's that no longer exists. If at some point an attempt is made to manipulate the child, enviromment->getActiveObject(child-id) returns NULL. Using the NULL pointer causes the crash...
Diffstat (limited to 'src')
-rw-r--r--src/script/lua_api/l_object.cpp5
1 files changed, 3 insertions, 2 deletions
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<int> child_ids = co->getAttachmentChildIds();
UNORDERED_SET<int>::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="<<co->getId()<<std::endl;