Prevent cache corruption when saving resources in the editor

(cherry picked from commit 496bd94c21)
This commit is contained in:
Yuri Sizov 2023-03-08 19:46:55 +01:00
parent 7490f89238
commit 048c252602
3 changed files with 22 additions and 2 deletions

View file

@ -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);
}