Skip to content

Commit bbe1203

Browse files
authoredApr 13, 2021
Attachments: Avoid data loss caused by set_attach() in callbacks (#11181)
1 parent 4d0fef8 commit bbe1203

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed
 

‎src/server/unit_sao.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,21 @@ void UnitSAO::setAttachment(int parent_id, const std::string &bone, v3f position
134134

135135
int old_parent = m_attachment_parent_id;
136136
m_attachment_parent_id = parent_id;
137+
138+
// The detach callbacks might call to setAttachment() again.
139+
// Ensure the attachment params are applied after this callback is run.
140+
if (parent_id != old_parent)
141+
onDetach(old_parent);
142+
143+
m_attachment_parent_id = parent_id;
137144
m_attachment_bone = bone;
138145
m_attachment_position = position;
139146
m_attachment_rotation = rotation;
140147
m_force_visible = force_visible;
141148
m_attachment_sent = false;
142149

143-
if (parent_id != old_parent) {
144-
onDetach(old_parent);
150+
if (parent_id != old_parent)
145151
onAttach(parent_id);
146-
}
147152
}
148153

149154
void UnitSAO::getAttachment(int *parent_id, std::string *bone, v3f *position,

0 commit comments

Comments
 (0)
Please sign in to comment.