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

[Editor] Prevent deferred tooltip update crash #102659

Merged
merged 1 commit into from
Feb 10, 2025

Conversation

AThousandShips
Copy link
Member

@AThousandShips AThousandShips commented Feb 10, 2025

Caused by TreeItems being accessed after clearing the tree on reset.

Can largely confirm this at least on 4.3, though without debug symbols I'm not sure if it is the same issue, can't reliably on 4.2, but hard to tell exactly why. I can reliably trigger it on debug builds, and with a few scenes in 4.4.beta3

Considered using ObjectID but I think this is a case where things should be solved by catching the problem at the source. This might still occur in edge cases where the timer fires during other updates, but this at least solves the issue reliably for me.

To trigger this bug:

  • Open several scenes
  • Edit the editor description of one of the root nodes
  • Switch quickly between the tabs

The editor should crash, caused by various errors of memory access related to TreeItem nodes, this would be because the deferred tooltip update holding a reference to a now freed TreeItem, relevant code is:

void SceneTreeEditor::_queue_update_node_tooltip(Node *p_node, TreeItem *p_item) {
Callable update_tooltip = callable_mp(this, &SceneTreeEditor::_update_node_tooltip);
if (update_node_tooltip_delay->is_connected("timeout", update_tooltip)) {
update_node_tooltip_delay->disconnect("timeout", update_tooltip);
}
update_node_tooltip_delay->connect("timeout", update_tooltip.bind(p_node, p_item));
update_node_tooltip_delay->start();
}

Where the timer set up, and:
if (p_node == get_scene_node() && p_node->get_scene_inherited_state().is_valid()) {
if (p_item->get_button_by_id(0, BUTTON_SUBSCENE) == -1) {
p_item->add_button(0, get_editor_theme_icon(SNAME("InstanceOptions")), BUTTON_SUBSCENE, false, TTR("Open in Editor"));
}
tooltip += String("\n" + TTR("Inherits:") + " " + p_node->get_scene_inherited_state()->get_path());
} else if (p_node != get_scene_node() && !p_node->get_scene_file_path().is_empty() && can_open_instance) {
if (p_item->get_button_by_id(0, BUTTON_SUBSCENE) == -1) {
p_item->add_button(0, get_editor_theme_icon(SNAME("InstanceOptions")), BUTTON_SUBSCENE, false, TTR("Open in Editor"));
}
tooltip += String("\n" + TTR("Instance:") + " " + p_node->get_scene_file_path());
}

Where the crash is triggered, due to accessing internal data of a freed node

Ability to trigger this might vary based on hardware and general performance as this is a timing issue

@AThousandShips AThousandShips added bug topic:editor crash cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release labels Feb 10, 2025
@AThousandShips AThousandShips added this to the 4.4 milestone Feb 10, 2025
@AThousandShips AThousandShips requested review from a team as code owners February 10, 2025 14:06
@AThousandShips AThousandShips changed the title [Editor] Prevent deferred update crash [Editor] Prevent deferred tooltip update crash Feb 10, 2025
Caused by `TreeItem`s being accessed after clearing the tree on reset.
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

@Repiteo Repiteo merged commit 9c7a42b into godotengine:master Feb 10, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Feb 10, 2025

Thanks!

@AThousandShips AThousandShips deleted the fix_tooltip_crash branch February 10, 2025 18:29
@AThousandShips
Copy link
Member Author

Thank you!

@akien-mga akien-mga removed the cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release label Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release crash topic:editor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants