Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CanvasItem notification thread guard #80752

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion scene/2d/node_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,17 @@ Point2 Node2D::to_global(Point2 p_local) const {
}

void Node2D::_notification(int p_notification) {
ERR_THREAD_GUARD;
switch (p_notification) {
case NOTIFICATION_ENTER_TREE: {
ERR_MAIN_THREAD_GUARD;

if (get_viewport()) {
get_parent()->connect(SNAME("child_order_changed"), callable_mp(get_viewport(), &Viewport::gui_set_root_order_dirty), CONNECT_REFERENCE_COUNTED);
}
} break;
case NOTIFICATION_EXIT_TREE: {
ERR_MAIN_THREAD_GUARD;

if (get_viewport()) {
get_parent()->disconnect(SNAME("child_order_changed"), callable_mp(get_viewport(), &Viewport::gui_set_root_order_dirty));
}
Expand Down
11 changes: 9 additions & 2 deletions scene/3d/node_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,9 @@ void Node3D::_propagate_transform_changed(Node3D *p_origin) {
}

void Node3D::_notification(int p_what) {
ERR_THREAD_GUARD;

switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
ERR_MAIN_THREAD_GUARD;
ERR_FAIL_NULL(get_tree());

Node *p = get_parent();
Expand Down Expand Up @@ -163,6 +162,8 @@ void Node3D::_notification(int p_what) {
} break;

case NOTIFICATION_EXIT_TREE: {
ERR_MAIN_THREAD_GUARD;

notification(NOTIFICATION_EXIT_WORLD, true);
if (xform_change.in_list()) {
get_tree()->xform_change_list.remove(&xform_change);
Expand All @@ -176,6 +177,8 @@ void Node3D::_notification(int p_what) {
} break;

case NOTIFICATION_ENTER_WORLD: {
ERR_MAIN_THREAD_GUARD;

data.inside_world = true;
data.viewport = nullptr;
Node *parent = get_parent();
Expand All @@ -198,6 +201,8 @@ void Node3D::_notification(int p_what) {
} break;

case NOTIFICATION_EXIT_WORLD: {
ERR_MAIN_THREAD_GUARD;

#ifdef TOOLS_ENABLED
clear_gizmos();
#endif
Expand All @@ -211,6 +216,8 @@ void Node3D::_notification(int p_what) {
} break;

case NOTIFICATION_TRANSFORM_CHANGED: {
ERR_THREAD_GUARD;

#ifdef TOOLS_ENABLED
for (int i = 0; i < data.gizmos.size(); i++) {
data.gizmos.write[i]->transform();
Expand Down
11 changes: 9 additions & 2 deletions scene/main/canvas_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,9 @@ void CanvasItem::_exit_canvas() {
}

void CanvasItem::_notification(int p_what) {
ERR_MAIN_THREAD_GUARD;

switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
ERR_MAIN_THREAD_GUARD;
ERR_FAIL_COND(!is_inside_tree());

Node *parent = get_parent();
Expand Down Expand Up @@ -336,6 +335,8 @@ void CanvasItem::_notification(int p_what) {

} break;
case NOTIFICATION_EXIT_TREE: {
ERR_MAIN_THREAD_GUARD;

if (xform_change.in_list()) {
get_tree()->xform_change_list.remove(&xform_change);
}
Expand All @@ -357,14 +358,20 @@ void CanvasItem::_notification(int p_what) {
} break;

case NOTIFICATION_VISIBILITY_CHANGED: {
ERR_MAIN_THREAD_GUARD;

emit_signal(SceneStringNames::get_singleton()->visibility_changed);
} break;
case NOTIFICATION_WORLD_2D_CHANGED: {
ERR_MAIN_THREAD_GUARD;

_exit_canvas();
_enter_canvas();
} break;
case NOTIFICATION_PARENTED: {
// The node is not inside the tree during this notification.
ERR_MAIN_THREAD_GUARD;

_notify_transform();
} break;
}
Expand Down
Loading