Skip to content

Commit 51b0379

Browse files
committed
Merge pull request #107397 from daniel080400/fix_lost_focus_crash
Fix crash when `save_on_focus_loss` is enabled
2 parents 042ad3a + aae5196 commit 51b0379

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

editor/editor_node.cpp

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,7 +1958,7 @@ void EditorNode::_save_scene_silently() {
19581958
// when Save on Focus Loss kicks in.
19591959
Node *scene = editor_data.get_edited_scene_root();
19601960
if (scene && !scene->get_scene_file_path().is_empty() && DirAccess::exists(scene->get_scene_file_path().get_base_dir())) {
1961-
_save_scene(scene->get_scene_file_path());
1961+
_save_scene(scene->get_scene_file_path(), -1, false);
19621962
save_editor_layout_delayed();
19631963
}
19641964
}
@@ -1986,23 +1986,29 @@ static void _reset_animation_mixers(Node *p_node, List<Pair<AnimationMixer *, Re
19861986
}
19871987
}
19881988

1989-
void EditorNode::_save_scene(String p_file, int idx) {
1989+
void EditorNode::_save_scene(String p_file, int idx, bool show_progress) {
19901990
ERR_FAIL_COND_MSG(!saving_scene.is_empty() && saving_scene == p_file, "Scene saved while already being saved!");
19911991

19921992
Node *scene = editor_data.get_edited_scene_root(idx);
19931993

1994-
save_scene_progress = memnew(EditorProgress("save", TTR("Saving Scene"), 3));
1995-
save_scene_progress->step(TTR("Analyzing"), 0);
1994+
if (show_progress) {
1995+
save_scene_progress = memnew(EditorProgress("save", TTR("Saving Scene"), 3));
1996+
save_scene_progress->step(TTR("Analyzing"), 0);
1997+
}
19961998

19971999
if (!scene) {
19982000
show_accept(TTR("This operation can't be done without a tree root."), TTR("OK"));
1999-
_close_save_scene_progress();
2001+
if (show_progress) {
2002+
_close_save_scene_progress();
2003+
}
20002004
return;
20012005
}
20022006

20032007
if (!scene->get_scene_file_path().is_empty() && _validate_scene_recursive(scene->get_scene_file_path(), scene)) {
20042008
show_accept(TTR("This scene can't be saved because there is a cyclic instance inclusion.\nPlease resolve it and then attempt to save again."), TTR("OK"));
2005-
_close_save_scene_progress();
2009+
if (show_progress) {
2010+
_close_save_scene_progress();
2011+
}
20062012
return;
20072013
}
20082014

@@ -2014,7 +2020,9 @@ void EditorNode::_save_scene(String p_file, int idx) {
20142020
_reset_animation_mixers(scene, &anim_backups);
20152021
_save_editor_states(p_file, idx);
20162022

2017-
save_scene_progress->step(TTR("Packing Scene"), 1);
2023+
if (show_progress) {
2024+
save_scene_progress->step(TTR("Packing Scene"), 1);
2025+
}
20182026

20192027
Ref<PackedScene> sdata;
20202028

@@ -2036,11 +2044,15 @@ void EditorNode::_save_scene(String p_file, int idx) {
20362044

20372045
if (err != OK) {
20382046
show_accept(TTR("Couldn't save scene. Likely dependencies (instances or inheritance) couldn't be satisfied."), TTR("OK"));
2039-
_close_save_scene_progress();
2047+
if (show_progress) {
2048+
_close_save_scene_progress();
2049+
}
20402050
return;
20412051
}
20422052

2043-
save_scene_progress->step(TTR("Saving scene"), 2);
2053+
if (show_progress) {
2054+
save_scene_progress->step(TTR("Saving scene"), 2);
2055+
}
20442056

20452057
int flg = 0;
20462058
if (EDITOR_GET("filesystem/on_save/compress_binary_resources")) {
@@ -2054,7 +2066,9 @@ void EditorNode::_save_scene(String p_file, int idx) {
20542066
emit_signal(SNAME("scene_saved"), p_file);
20552067
editor_data.notify_scene_saved(p_file);
20562068

2057-
save_scene_progress->step(TTR("Saving external resources"), 3);
2069+
if (show_progress) {
2070+
save_scene_progress->step(TTR("Saving external resources"), 3);
2071+
}
20582072

20592073
_save_external_resources();
20602074
saving_scene = p_file; // Some editors may save scenes of built-in resources as external data, so avoid saving this scene again.
@@ -2080,7 +2094,9 @@ void EditorNode::_save_scene(String p_file, int idx) {
20802094

20812095
scene->propagate_notification(NOTIFICATION_EDITOR_POST_SAVE);
20822096
_update_unsaved_cache();
2083-
_close_save_scene_progress();
2097+
if (show_progress) {
2098+
_close_save_scene_progress();
2099+
}
20842100
}
20852101

20862102
void EditorNode::save_all_scenes() {

editor/editor_node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ class EditorNode : public Node {
588588
void _set_current_scene(int p_idx);
589589
void _set_current_scene_nocheck(int p_idx);
590590
bool _validate_scene_recursive(const String &p_filename, Node *p_node);
591-
void _save_scene(String p_file, int idx = -1);
591+
void _save_scene(String p_file, int idx = -1, bool show_progress = true);
592592
void _save_all_scenes();
593593
int _next_unsaved_scene(bool p_valid_filename, int p_start = 0);
594594
void _discard_changes(const String &p_str = String());

0 commit comments

Comments
 (0)