Merge pull request #74615 from YuriSizov/editor-prevent-corruption-when-saving-resources
Prevent cache corruption when saving resources in the editor
This commit is contained in:
commit
c69ec6557c
@ -1293,6 +1293,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) {
|
void EditorNode::save_resource_in_path(const Ref<Resource> &p_resource, const String &p_path) {
|
||||||
editor_data.apply_changes_in_editors();
|
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;
|
int flg = 0;
|
||||||
if (EDITOR_GET("filesystem/on_save/compress_binary_resources")) {
|
if (EDITOR_GET("filesystem/on_save/compress_binary_resources")) {
|
||||||
flg |= ResourceSaver::FLAG_COMPRESS;
|
flg |= ResourceSaver::FLAG_COMPRESS;
|
||||||
@ -1307,10 +1313,16 @@ void EditorNode::save_resource_in_path(const Ref<Resource> &p_resource, const St
|
|||||||
} else {
|
} else {
|
||||||
show_accept(TTR("Error saving resource!"), TTR("OK"));
|
show_accept(TTR("Error saving resource!"), TTR("OK"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
saving_resources_in_path.erase(p_resource);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
((Resource *)p_resource.ptr())->set_path(path);
|
((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);
|
emit_signal(SNAME("resource_saved"), p_resource);
|
||||||
editor_data.notify_resource_saved(p_resource);
|
editor_data.notify_resource_saved(p_resource);
|
||||||
}
|
}
|
||||||
@ -6511,6 +6523,11 @@ void EditorNode::_renderer_selected(int p_which) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EditorNode::_resource_saved(Ref<Resource> p_resource, const String &p_path) {
|
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()) {
|
if (EditorFileSystem::get_singleton()) {
|
||||||
EditorFileSystem::get_singleton()->update_file(p_path);
|
EditorFileSystem::get_singleton()->update_file(p_path);
|
||||||
}
|
}
|
||||||
|
@ -486,6 +486,7 @@ private:
|
|||||||
Object *current = nullptr;
|
Object *current = nullptr;
|
||||||
|
|
||||||
Ref<Resource> saving_resource;
|
Ref<Resource> saving_resource;
|
||||||
|
HashSet<Ref<Resource>> saving_resources_in_path;
|
||||||
|
|
||||||
uint64_t update_spinner_step_msec = 0;
|
uint64_t update_spinner_step_msec = 0;
|
||||||
uint64_t update_spinner_step_frame = 0;
|
uint64_t update_spinner_step_frame = 0;
|
||||||
|
@ -1010,12 +1010,14 @@ void GDScript::_bind_methods() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GDScript::set_path(const String &p_path, bool p_take_over) {
|
void GDScript::set_path(const String &p_path, bool p_take_over) {
|
||||||
String old_path = path;
|
|
||||||
if (is_root_script()) {
|
if (is_root_script()) {
|
||||||
Script::set_path(p_path, p_take_over);
|
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);
|
GDScriptCache::move_script(old_path, p_path);
|
||||||
|
|
||||||
for (KeyValue<StringName, Ref<GDScript>> &kv : subclasses) {
|
for (KeyValue<StringName, Ref<GDScript>> &kv : subclasses) {
|
||||||
kv.value->set_path(p_path, p_take_over);
|
kv.value->set_path(p_path, p_take_over);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user