avoid clearChildAttachments iterator invalidation (#12987)

This commit is contained in:
Jude Melton-Houghton 2022-11-23 14:48:12 -05:00 committed by GitHub
parent 386bfcda2b
commit 9527cc3fa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -179,12 +179,16 @@ void UnitSAO::getAttachment(int *parent_id, std::string *bone, v3f *position,
void UnitSAO::clearChildAttachments()
{
for (int child_id : m_attachment_child_ids) {
// Cannot use for-loop here: setAttachment() modifies 'm_attachment_child_ids'!
while (!m_attachment_child_ids.empty()) {
int child_id = *m_attachment_child_ids.begin();
// Child can be NULL if it was deleted earlier
if (ServerActiveObject *child = m_env->getActiveObject(child_id))
child->setAttachment(0, "", v3f(0, 0, 0), v3f(0, 0, 0), false);
removeAttachmentChild(child_id);
}
m_attachment_child_ids.clear();
}
void UnitSAO::clearParentAttachment()