diff options
author | SmallJoker <SmallJoker@users.noreply.github.com> | 2021-04-13 20:02:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-13 20:02:18 +0200 |
commit | bbe120308f2944eade833b4f16cfc3b42b01fa34 (patch) | |
tree | d5adae35c0b2661e2f554c230aba6b1c3978b6f8 /src | |
parent | 4d0fef8ae87aa7b940d43485e7f6466eaa3d111e (diff) | |
download | minetest-bbe120308f2944eade833b4f16cfc3b42b01fa34.tar.gz minetest-bbe120308f2944eade833b4f16cfc3b42b01fa34.tar.bz2 minetest-bbe120308f2944eade833b4f16cfc3b42b01fa34.zip |
Attachments: Avoid data loss caused by set_attach() in callbacks (#11181)
Diffstat (limited to 'src')
-rw-r--r-- | src/server/unit_sao.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/server/unit_sao.cpp b/src/server/unit_sao.cpp index 2371640ca..fa6c8f0f4 100644 --- a/src/server/unit_sao.cpp +++ b/src/server/unit_sao.cpp @@ -134,16 +134,21 @@ void UnitSAO::setAttachment(int parent_id, const std::string &bone, v3f position int old_parent = m_attachment_parent_id; m_attachment_parent_id = parent_id; + + // The detach callbacks might call to setAttachment() again. + // Ensure the attachment params are applied after this callback is run. + if (parent_id != old_parent) + onDetach(old_parent); + + m_attachment_parent_id = parent_id; m_attachment_bone = bone; m_attachment_position = position; m_attachment_rotation = rotation; m_force_visible = force_visible; m_attachment_sent = false; - if (parent_id != old_parent) { - onDetach(old_parent); + if (parent_id != old_parent) onAttach(parent_id); - } } void UnitSAO::getAttachment(int *parent_id, std::string *bone, v3f *position, |