1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-06 12:20:30 +00:00

Merge pull request #49741 from RandomShaper/fix_save_scene_side_effects

Remove side effects of scene save
This commit is contained in:
Rémi Verschelde
2021-06-20 00:37:38 +02:00
committed by GitHub
2 changed files with 10 additions and 10 deletions

View File

@@ -1625,15 +1625,6 @@ void EditorNode::_save_scene(String p_file, int idx) {
return; return;
} }
// force creation of node path cache
// (hacky but needed for the tree to update properly)
Node *dummy_scene = sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE);
if (!dummy_scene) {
show_accept(TTR("Couldn't save scene. Likely dependencies (instances or inheritance) couldn't be satisfied."), TTR("OK"));
return;
}
memdelete(dummy_scene);
int flg = 0; int flg = 0;
if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) { if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) {
flg |= ResourceSaver::FLAG_COMPRESS; flg |= ResourceSaver::FLAG_COMPRESS;

View File

@@ -893,6 +893,13 @@ Error SceneState::pack(Node *p_scene) {
node_paths.write[E->get()] = scene->get_path_to(E->key()); node_paths.write[E->get()] = scene->get_path_to(E->key());
} }
if (Engine::get_singleton()->is_editor_hint()) {
// Build node path cache
for (Map<Node *, int>::Element *E = node_map.front(); E; E = E->next()) {
node_path_cache[scene->get_path_to(E->key())] = E->get();
}
}
return OK; return OK;
} }
@@ -927,10 +934,12 @@ Ref<SceneState> SceneState::_get_base_scene_state() const {
} }
int SceneState::find_node_by_path(const NodePath &p_node) const { int SceneState::find_node_by_path(const NodePath &p_node) const {
ERR_FAIL_COND_V_MSG(node_path_cache.size() == 0, -1, "This operation requires the node cache to have been built.");
if (!node_path_cache.has(p_node)) { if (!node_path_cache.has(p_node)) {
if (_get_base_scene_state().is_valid()) { if (_get_base_scene_state().is_valid()) {
int idx = _get_base_scene_state()->find_node_by_path(p_node); int idx = _get_base_scene_state()->find_node_by_path(p_node);
if (idx >= 0) { if (idx != -1) {
int rkey = _find_base_scene_node_remap_key(idx); int rkey = _find_base_scene_node_remap_key(idx);
if (rkey == -1) { if (rkey == -1) {
rkey = nodes.size() + base_scene_node_remap.size(); rkey = nodes.size() + base_scene_node_remap.size();