### Godot version

4.2.dev [202e4b2c1e7f8b25738b93d0e4d5066453d3edf3]

### System information

Godot v4.2.dev (202e4b2c1e) - SteamOS holo - X11 - Vulkan (Forward+) - integrated AMD Custom GPU 0405 (RADV VANGOGH) () - AMD Custom APU 0405 (8 Threads)

### Issue description

Opening any project with Godot COULD emit error message `Index p_idx = -1 is out of bounds (edited_scene.size() = 1).`. This error message will be visible in Godot editor as well as in the terminal (if Godot is opened from terminal).

After some debugging, I have come to following conclusion and found the root cause. Godot editor saves the editor state like the list of all opened scenes and the current edited scene in `.godot/editor/editor_layout.cfg` (project relative path). The problem is that current edited scene (represented as `current_scene` in `EditorNode` section of the configuration file) was not updated when all scenes are closed while the list of all opened scenes is properly updated. This leaves the value for `current_scene` to the value from the previous Godot editor launch:

```
[EditorNode]

open_scenes=PackedStringArray()
current_scene="res://scenes/node2.tscn"
center_split_offset=0
selected_default_debugger_tab_idx=0
selected_main_editor_idx=1
```

Godot editor, when started, will read this configuration file and open all scenes listed in `open_scenes` and select the scene tab represented by `current_scene`. Since `res://scenes/node2.tscn` is not found in the list of opened scenes, the error message is emitted:

```
ERROR: Index p_idx = -1 is out of bounds (edited_scene.size() = 1).
```

Issue was introduced in:

```
commit 454befc880f391448bbd1dce56a38897f5dd3037
Author: Alex Drozd <drozdster@gmail.com>
Date:   Mon Jun 12 20:00:42 2023 +0200

    Prevent non-existent scene from being saved to persistent editor config
```

It is only reproducible on master branch.

### Steps to reproduce

This issue can be reproduced with ANY project by following steps:

1. Start Godot editor.
2. Open a scene (any one).
3. Quit Godot editor.
4. Start Godot editor.
5. Close the opened scene. The issue can only be triggered when you closed ALL opened scenes.
6. Quit Godot editor.
7. Start Godot editor.

### Minimal reproduction project

N/A
#include "editor/plugins/node_3d_editor_plugin.h"
#include "editor/plugins/packed_scene_translation_parser_plugin.h"
#include "editor/plugins/root_motion_editor_plugin.h"
#include "editor/plugins/script_text_editor.h"
#include "editor/plugins/text_editor.h"
#include "editor/plugins/version_control_editor_plugin.h"
#include "editor/plugins/visual_shader_editor_plugin.h"
#include "editor/progress_dialog.h"
#include "editor/project_settings_editor.h"
#include "editor/register_exporters.h"
#include "editor/scene_tree_dock.h"
#include "editor/window_wrapper.h"
#include <stdio.h>
#include <stdlib.h>
EditorNode *EditorNode::singleton = nullptr;
static const String META_TEXT_TO_COPY = "text_to_copy";
static const String EDITOR_NODE_CONFIG_SECTION = "EditorNode";
void EditorNode::disambiguate_filenames(const Vector<String> p_full_paths, Vector<String> &r_filenames) {
	ERR_FAIL_COND_MSG(p_full_paths.size() != r_filenames.size(), vformat("disambiguate_filenames requires two string vectors of same length (%d != %d).", p_full_paths.size(), r_filenames.size()));
	
	
	Vector<RBSet<int>> index_sets;
	HashMap<String, int> scene_name_to_set_index;
	for (int i = 0; i < r_filenames.size(); i++) {
		String scene_name = r_filenames[i];
		if (!scene_name_to_set_index.has(scene_name)) {
			index_sets.append(RBSet<int>());
			scene_name_to_set_index.insert(r_filenames[i], index_sets.size() - 1);
		}
		index_sets.write[scene_name_to_set_index[scene_name]].insert(i);