mirror of
https://github.com/minetest/minetest.git
synced 2024-11-24 00:23:46 +01:00
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...
This commit is contained in:
parent
e4031156f1
commit
1980d9ea31
@ -140,7 +140,8 @@ int ObjectRef::l_remove(lua_State *L)
|
|||||||
UNORDERED_SET<int> child_ids = co->getAttachmentChildIds();
|
UNORDERED_SET<int> child_ids = co->getAttachmentChildIds();
|
||||||
UNORDERED_SET<int>::iterator it;
|
UNORDERED_SET<int>::iterator it;
|
||||||
for (it = child_ids.begin(); it != child_ids.end(); ++it) {
|
for (it = child_ids.begin(); it != child_ids.end(); ++it) {
|
||||||
ServerActiveObject *child = env->getActiveObject(*it);
|
// 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));
|
child->setAttachment(0, "", v3f(0, 0, 0), v3f(0, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user