-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
Correctly free relevant scripts when closing scene tabs #86008
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
You should target If you need more information about the update process please see: here. If wanted I can fix the branch for you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some style fixes (will help as you need to push again to cause CI to run)
I don't think adding this Original Logicvoid EditorNode::_remove_edited_scene(bool p_change_tab) {
// When scene gets closed no node is edited anymore, so make sure the editors are notified before nodes are freed.
hide_unused_editors(SceneTreeDock::get_singleton());
int new_index = editor_data.get_edited_scene();
int old_index = new_index;
if (new_index > 0) {
new_index = new_index - 1;
} else if (editor_data.get_edited_scene_count() > 1) {
new_index = 1;
} else {
editor_data.add_edited_scene(-1);
new_index = 1;
}
if (p_change_tab) {
_set_current_scene(new_index);
}
editor_data.remove_scene(old_index);
_update_title();
scene_tabs->update_scene_tabs();
} New Logic that Causes Crashingvoid EditorNode::_remove_edited_scene(bool p_change_tab) {
// When scene gets closed no node is edited anymore, so make sure the editors are notified before nodes are freed.
hide_unused_editors(SceneTreeDock::get_singleton());
int old_index = editor_data.get_edited_scene();
editor_data.remove_scene(old_index);
if (p_change_tab) {
int new_index = editor_data.get_edited_scene();
if (new_index == 0) {
if (editor_data.get_edited_scene_count() == 0) {
editor_data.add_edited_scene(-1);
}
} else {
new_index = new_index - 1;
}
_set_current_scene(new_index);
}
_update_title();
scene_tabs->update_scene_tabs();
} The Crash Message
|
I checked why the tab updates while deleting and seems like when closing the tab, The fix here looks like a workaround for bad tab management. |
Detailed reproduction steps are written in issue #85983. |
I know, I just don't have a C# setup to test. I tried with GDScript and other resources and it doesn't seem to happen.
It's already merged, please give it a test. |
The test indicates the issue persists to exist. |
Well the issue is still updating the tabs before the old tab was completely removed. So I think a better solution would be delaying tab update. |
I will try that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tab update now happens after tab is fully removed, so if it fixes the issue, then it's fine.
On unrelated note, I think we should be more conservative with calling tab updates. There are cases like call to _set_current_scene()
followed by update_scene_tabs()
, which makes the update happen twice, because _set_current_scene()
already does this internally. Tab update is now cheaper, but it's still called more than necessary.
Could you please squash your commits into one? Make sure that the final commit has a short but descriptive message (the title of this PR is a good option). See this documentation, if you need help with squashing. |
Thanks, and congrats on your first merged Godot contribution! |
Fixes #85983
EditorNode::_remove_scene
fromeditor/editor_node.cpp
callseditor_data.clear_script_icon_cache()
for cleaning all script icon cache, previously, the implementation inside_remove_edited_scene(p_change_tab)
loops through all scene tabs including the one we are closing, results in a call toEditorData::get_script_icon()
on the closing scene tab, and createRef<Script>
s to that unloading scene lives inside_script_icon_cache
.This issue causes, primarily, the c-sharp scripts not to get freed when closing scene tabs, and might be a cause of #78513.
These wild script references may live inside the
ScriptManagerBridge.ScriptTypeBiMap
, resulting in the duplicate key issue when unloading the assebly.