Skip to content

Commit aae5196

Browse files
committed
Fix crash when save_on_focus_loss is enabled
1 parent 1bbfe63 commit aae5196

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
@@ -1957,7 +1957,7 @@ void EditorNode::_save_scene_silently() {
19571957
// when Save on Focus Loss kicks in.
19581958
Node *scene = editor_data.get_edited_scene_root();
19591959
if (scene && !scene->get_scene_file_path().is_empty() && DirAccess::exists(scene->get_scene_file_path().get_base_dir())) {
1960-
_save_scene(scene->get_scene_file_path());
1960+
_save_scene(scene->get_scene_file_path(), -1, false);
19611961
save_editor_layout_delayed();
19621962
}
19631963
}
@@ -1985,23 +1985,29 @@ static void _reset_animation_mixers(Node *p_node, List<Pair<AnimationMixer *, Re
19851985
}
19861986
}
19871987

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

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

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

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

20022006
if (!scene->get_scene_file_path().is_empty() && _validate_scene_recursive(scene->get_scene_file_path(), scene)) {
20032007
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"));
2004-
_close_save_scene_progress();
2008+
if (show_progress) {
2009+
_close_save_scene_progress();
2010+
}
20052011
return;
20062012
}
20072013

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

2016-
save_scene_progress->step(TTR("Packing Scene"), 1);
2022+
if (show_progress) {
2023+
save_scene_progress->step(TTR("Packing Scene"), 1);
2024+
}
20172025

20182026
Ref<PackedScene> sdata;
20192027

@@ -2035,11 +2043,15 @@ void EditorNode::_save_scene(String p_file, int idx) {
20352043

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

2042-
save_scene_progress->step(TTR("Saving scene"), 2);
2052+
if (show_progress) {
2053+
save_scene_progress->step(TTR("Saving scene"), 2);
2054+
}
20432055

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

2056-
save_scene_progress->step(TTR("Saving external resources"), 3);
2068+
if (show_progress) {
2069+
save_scene_progress->step(TTR("Saving external resources"), 3);
2070+
}
20572071

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

20802094
scene->propagate_notification(NOTIFICATION_EDITOR_POST_SAVE);
20812095
_update_unsaved_cache();
2082-
_close_save_scene_progress();
2096+
if (show_progress) {
2097+
_close_save_scene_progress();
2098+
}
20832099
}
20842100

20852101
void EditorNode::save_all_scenes() {

editor/editor_node.h

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

0 commit comments

Comments
 (0)