summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Sizov <yuris@humnom.net>2023-03-08 19:46:55 +0100
committerYuri Sizov <yuris@humnom.net>2023-03-13 14:16:13 +0100
commit048c252602aa9e21175b7e125dbcae204e303b1f (patch)
treeb20fef4f58dacf5994ca3049d24ef9e934f01835
parent7490f892387662bc14b77b4992fe66a9c678fb5c (diff)
Prevent cache corruption when saving resources in the editor
(cherry picked from commit 496bd94c21dbda01fc7d9d0a108eecef21924024)
-rw-r--r--editor/editor_node.cpp17
-rw-r--r--editor/editor_node.h1
-rw-r--r--modules/gdscript/gdscript.cpp6
3 files changed, 22 insertions, 2 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 6fcf092834..2834a086b8 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -1233,6 +1233,12 @@ void EditorNode::edit_resource(const Ref<Resource> &p_resource) {
void EditorNode::save_resource_in_path(const Ref<Resource> &p_resource, const String &p_path) {
editor_data.apply_changes_in_editors();
+
+ if (saving_resources_in_path.has(p_resource)) {
+ return;
+ }
+ saving_resources_in_path.insert(p_resource);
+
int flg = 0;
if (EDITOR_GET("filesystem/on_save/compress_binary_resources")) {
flg |= ResourceSaver::FLAG_COMPRESS;
@@ -1247,10 +1253,16 @@ void EditorNode::save_resource_in_path(const Ref<Resource> &p_resource, const St
} else {
show_accept(TTR("Error saving resource!"), TTR("OK"));
}
+
+ saving_resources_in_path.erase(p_resource);
return;
}
((Resource *)p_resource.ptr())->set_path(path);
+ saving_resources_in_path.erase(p_resource);
+
+ _resource_saved(p_resource, path);
+
emit_signal(SNAME("resource_saved"), p_resource);
editor_data.notify_resource_saved(p_resource);
}
@@ -6441,6 +6453,11 @@ void EditorNode::_renderer_selected(int p_which) {
}
void EditorNode::_resource_saved(Ref<Resource> p_resource, const String &p_path) {
+ if (singleton->saving_resources_in_path.has(p_resource)) {
+ // This is going to be handled by save_resource_in_path when the time is right.
+ return;
+ }
+
if (EditorFileSystem::get_singleton()) {
EditorFileSystem::get_singleton()->update_file(p_path);
}
diff --git a/editor/editor_node.h b/editor/editor_node.h
index 8ad5969249..6a9d052791 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -485,6 +485,7 @@ private:
Object *current = nullptr;
Ref<Resource> saving_resource;
+ HashSet<Ref<Resource>> saving_resources_in_path;
uint64_t update_spinner_step_msec = 0;
uint64_t update_spinner_step_frame = 0;
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp
index b6caefbdb5..1a1d021dbc 100644
--- a/modules/gdscript/gdscript.cpp
+++ b/modules/gdscript/gdscript.cpp
@@ -1010,12 +1010,14 @@ void GDScript::_bind_methods() {
}
void GDScript::set_path(const String &p_path, bool p_take_over) {
- String old_path = path;
if (is_root_script()) {
Script::set_path(p_path, p_take_over);
}
- this->path = p_path;
+
+ String old_path = path;
+ path = p_path;
GDScriptCache::move_script(old_path, p_path);
+
for (KeyValue<StringName, Ref<GDScript>> &kv : subclasses) {
kv.value->set_path(p_path, p_take_over);
}