Skip to content

Commit

Permalink
Fix crash when attached object no longer exists
Browse files Browse the repository at this point in the history
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...
  • Loading branch information
Rogier-5 authored and nerzhul committed Nov 13, 2016
1 parent e403115 commit 1980d9e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/script/lua_api/l_object.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit 1980d9e

Please sign in to comment.