Skip to content

Commit

Permalink
Attachments: Avoid data loss caused by set_attach() in callbacks (#11181
Browse files Browse the repository at this point in the history
)
  • Loading branch information
SmallJoker committed Apr 13, 2021
1 parent 4d0fef8 commit bbe1203
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/server/unit_sao.cpp
Expand Up @@ -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,
Expand Down

0 comments on commit bbe1203

Please sign in to comment.