aboutsummaryrefslogtreecommitdiff
path: root/src/server/unit_sao.cpp
diff options
context:
space:
mode:
authorJude Melton-Houghton <jwmhjwmh@gmail.com>2022-11-23 14:48:12 -0500
committerGitHub <noreply@github.com>2022-11-23 14:48:12 -0500
commit9527cc3fa081ded4280765b6d805bf1bcc6591b9 (patch)
tree4c72fa6f6b04bd29007946e56195465bba00b01b /src/server/unit_sao.cpp
parent386bfcda2b3565b38c79af76743ad3d76c452fd5 (diff)
downloadminetest-9527cc3fa081ded4280765b6d805bf1bcc6591b9.tar.xz
avoid clearChildAttachments iterator invalidation (#12987)
Diffstat (limited to 'src/server/unit_sao.cpp')
-rw-r--r--src/server/unit_sao.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/server/unit_sao.cpp b/src/server/unit_sao.cpp
index 9a49b0f43..6fdefaad4 100644
--- a/src/server/unit_sao.cpp
+++ b/src/server/unit_sao.cpp
@@ -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()