Skip to content

Commit

Permalink
Fix CanvasItem not exiting its canvas group on canvas exit
Browse files Browse the repository at this point in the history
  • Loading branch information
kleonc committed Jul 20, 2022
1 parent e830d9d commit 558b96f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions scene/2d/canvas_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,16 +530,16 @@ void CanvasItem::_enter_canvas() {

VisualServer::get_singleton()->canvas_item_set_parent(canvas_item, canvas);

group = "root_canvas" + itos(canvas.get_id());
canvas_group = "root_canvas" + itos(canvas.get_id());

add_to_group(group);
add_to_group(canvas_group);
if (canvas_layer) {
canvas_layer->reset_sort_index();
} else {
get_viewport()->gui_reset_canvas_sort_index();
}

get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE, group, "_toplevel_raise_self");
get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE, canvas_group, "_toplevel_raise_self");

} else {
CanvasItem *parent = get_parent_item();
Expand All @@ -558,7 +558,10 @@ void CanvasItem::_exit_canvas() {
notification(NOTIFICATION_EXIT_CANVAS, true); //reverse the notification
VisualServer::get_singleton()->canvas_item_set_parent(canvas_item, RID());
canvas_layer = nullptr;
group = "";
if (canvas_group != "") {
remove_from_group(canvas_group);
canvas_group = "";
}
}

void CanvasItem::_notification(int p_what) {
Expand All @@ -584,8 +587,8 @@ void CanvasItem::_notification(int p_what) {
break;
}

if (group != "") {
get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE, group, "_toplevel_raise_self");
if (canvas_group != "") {
get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE, canvas_group, "_toplevel_raise_self");
} else {
CanvasItem *p = get_parent_item();
ERR_FAIL_COND(!p);
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/canvas_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class CanvasItem : public Node {
mutable SelfList<Node> xform_change;

RID canvas_item;
String group;
String canvas_group;

CanvasLayer *canvas_layer;

Expand Down

0 comments on commit 558b96f

Please sign in to comment.