Fix transform notification in threaded processing.

This commit is contained in:
X23 2026-02-07 16:37:15 +08:00
parent 56f3e2611d
commit 44fa4a4cde
2 changed files with 8 additions and 7 deletions

View file

@ -122,10 +122,11 @@ void Node3D::_propagate_transform_changed(Node3D *p_origin) {
#else
if (data.notify_transform && !data.ignore_notification && !xform_change.in_list()) {
#endif
if (likely(is_accessible_from_caller_thread())) {
// SceneTree::xform_change_list is not thread safe to modify, and is read by the main thread when processings are done.
if (Thread::is_main_thread()) {
get_tree()->xform_change_list.add(&xform_change);
} else {
// This should very rarely happen, but if it does at least make sure the notification is received eventually.
// For any threaded-processed node, add it to xform_change_list on the main thread in a deferred manner.
callable_mp(this, &Node3D::_propagate_transform_changed_deferred).call_deferred();
}
}

View file

@ -1096,10 +1096,6 @@ void Node::_remove_tree_from_process_thread_group() {
}
void Node::_add_tree_to_process_thread_group(Node *p_owner) {
if (_is_any_processing()) {
_add_to_process_thread_group();
}
data.process_thread_group_owner = p_owner;
if (p_owner != nullptr) {
data.process_group = p_owner->data.process_group;
@ -1107,12 +1103,16 @@ void Node::_add_tree_to_process_thread_group(Node *p_owner) {
data.process_group = &data.tree->default_process_group;
}
if (_is_any_processing()) {
_add_to_process_thread_group();
}
for (KeyValue<StringName, Node *> &K : data.children) {
if (K.value->data.process_thread_group != PROCESS_THREAD_GROUP_INHERIT) {
continue;
}
K.value->_add_to_process_thread_group();
K.value->_add_tree_to_process_thread_group(p_owner);
}
}
bool Node::is_processing_internal() const {