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

[3.x] Fix CanvasItem visibility propagation #58281

Closed
wants to merge 1 commit into from

Conversation

timothyqiu
Copy link
Member

Fixes #58251

I believe the logic is also wrong on master, see #58251 (comment). But I'm not sure if a similar fix would cancel the optimization of #57684 on master. Since the issue is currently only reproducible on 3.x, this PR only targets 3.x.


The name of p_was_visible parameter is no accurate. It's only "was visible" if the node is the source of the propagation. It's always false for other nodes in the propagation chain, making the name awkward. The only place that passes the parameter is set_visible():

_propagate_visibility_changed(p_visible, !p_visible);

When used, it only makes sense if it's true:

} else if (!p_visible && (visible || p_was_visible)) {
emit_signal(SceneStringNames::get_singleton()->hide);
}

So I changed it to p_is_source so it's easier to understand. The above code will emit the signal when it's propagating "hide" and if the current node is visible or the current node is the source of propagation.


The actual cause of the issue is line 360:

void CanvasItem::_propagate_visibility_changed(bool p_visible, bool p_was_visible) {
if (p_visible && first_draw) { //avoid propagating it twice
first_draw = false;
}
parent_visible_in_tree = p_visible;
notification(NOTIFICATION_VISIBILITY_CHANGED);

  1. When toggling visibility of a CanvasItem, this syncs parent_is_visible_in_tree with it. This should only happen for other nodes in the propagation chain, not for the node itself.
  2. For other nodes in the propagation chain, p_visible is the visible of the propagation source, it does not have to be the same as its is_visible_in_tree(). So a proper check like in NOTIFICATION_ENTER_TREE should be done.

@akien-mga
Copy link
Member

Superseded by #58386.

@akien-mga akien-mga closed this Feb 21, 2022
@timothyqiu timothyqiu deleted the propagate-visible-3.x branch February 22, 2022 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants