### Godot version

4.1 dev2

### System information

Windows 10 x64

### Issue description

```
CrashHandlerException: Program crashed
Engine version: Godot Engine v4.1.dev.custom_build (554a1e2485abe728346ed9f239cf67a7e0e394a3)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[0] Node::_propagate_ready (C:\godot_source\scene\main\node.cpp:177)
[1] Node::_propagate_ready (C:\godot_source\scene\main\node.cpp:181)
[2] Node::_set_tree (C:\godot_source\scene\main\node.cpp:2628)
[3] Node::_add_child_nocheck (C:\godot_source\scene\main\node.cpp:1143)
[4] Node::add_child (C:\godot_source\scene\main\node.cpp:1160)
[5] EditorNode::set_edited_scene (C:\godot_source\editor\editor_node.cpp:3455)
[6] EditorNode::load_scene (C:\godot_source\editor\editor_node.cpp:3753)
[7] EditorNode::open_request (C:\godot_source\editor\editor_node.cpp:3937)
[8] EditorNode::_menu_option_confirm (C:\godot_source\editor\editor_node.cpp:2560)
[9] EditorNode::_menu_option (C:\godot_source\editor\editor_node.cpp:1419)
[10] call_with_variant_args_helper<EditorNode,int,0> (C:\godot_source\core\variant\binder_common.h:308)
[11] call_with_variant_args<EditorNode,int> (C:\godot_source\core\variant\binder_common.h:418)
[12] CallableCustomMethodPointer<EditorNode,int>::call (C:\godot_source\core\object\callable_method_pointer.h:105)
[13] Callable::callp (C:\godot_source\core\variant\callable.cpp:51)
[14] Object::emit_signalp (C:\godot_source\core\object\object.cpp:1065)
[15] Object::emit_signal<int> (C:\godot_source\core\object\object.h:868)
[16] PopupMenu::activate_item (C:\godot_source\scene\gui\popup_menu.cpp:1822)
[17] PopupMenu::activate_item_by_event (C:\godot_source\scene\gui\popup_menu.cpp:1744)
[18] MenuBar::shortcut_input (C:\godot_source\scene\gui\menu_bar.cpp:166)
[19] Node::_call_shortcut_input (C:\godot_source\scene\main\node.cpp:2815)
[20] SceneTree::_call_input_pause (C:\godot_source\scene\main\scene_tree.cpp:957)
[21] Viewport::push_unhandled_input (C:\godot_source\scene\main\viewport.cpp:2943)
[22] Viewport::push_input (C:\godot_source\scene\main\viewport.cpp:2914)
[23] Window::_window_input (C:\godot_source\scene\main\window.cpp:1387)
[24] call_with_variant_args_helper<Window,Ref<InputEvent> const &,0> (C:\godot_source\core\variant\binder_common.h:303)
[25] call_with_variant_args<Window,Ref<InputEvent> const &> (C:\godot_source\core\variant\binder_common.h:418)
[26] CallableCustomMethodPointer<Window,Ref<InputEvent> const &>::call (C:\godot_source\core\object\callable_method_pointer.h:105)
[27] Callable::callp (C:\godot_source\core\variant\callable.cpp:51)
[28] DisplayServerWindows::_dispatch_input_event (C:\godot_source\platform\windows\display_server_windows.cpp:2297)
[29] DisplayServerWindows::_dispatch_input_events (C:\godot_source\platform\windows\display_server_windows.cpp:2262)
[30] Input::_parse_input_event_impl (C:\godot_source\core\input\input.cpp:706)
[31] Input::flush_buffered_events (C:\godot_source\core\input\input.cpp:964)
[32] DisplayServerWindows::process_events (C:\godot_source\platform\windows\display_server_windows.cpp:1991)
[33] OS_Windows::run (C:\godot_source\platform\windows\os_windows.cpp:1475)
[34] widechar_main (C:\godot_source\platform\windows\godot_windows.cpp:181)
[35] _main (C:\godot_source\platform\windows\godot_windows.cpp:203)
[36] main (C:\godot_source\platform\windows\godot_windows.cpp:217)
[37] WinMain (C:\godot_source\platform\windows\godot_windows.cpp:231)
[38] __scrt_common_main_seh (D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
[39] <couldn't map PC to fn name>
-- END OF BACKTRACE --
```
Not sure what causes this, but I managed to isolate it. It's related to one of my scripts, but the stack trace doesn't really point to anything specific.

It doesn't crash in 4.0.2

### Steps to reproduce

1. Open the MRP
2. Open CrashHere.tscn
3. If it doesn't crash, close the scene and open again (it doesn't always happen)

### Minimal reproduction project

[YAC.zip](https://github.com/godotengine/godot/files/11436916/YAC.zip)
The crash seems to be caused by the NPC script.
}
	if (!get_scene_file_path().is_empty()) { //an instance
		node->set_scene_file_path(get_scene_file_path());
		node->data.editable_instance = data.editable_instance;
	}
	StringName script_property_name = CoreStringNames::get_singleton()->_script;
	List<const Node *> hidden_roots;
	List<const Node *> node_tree;
	node_tree.push_front(this);
	if (instantiated) {
		// Since nodes in the instantiated hierarchy won't be duplicated explicitly, we need to make an inventory
		// of all the nodes in the tree of the instantiated scene in order to transfer the values of the properties
		Vector<const Node *> instance_roots;
		instance_roots.push_back(this);
		for (List<const Node *>::Element *N = node_tree.front(); N; N = N->next()) {
			for (int i = 0; i < N->get()->get_child_count(); ++i) {
				Node *descendant = N->get()->get_child(i);
				// Skip nodes not really belonging to the instantiated hierarchy; they'll be processed normally later
				// but remember non-instantiated nodes that are hidden below instantiated ones
				if (!instance_roots.has(descendant->get_owner())) {
					if (descendant->get_parent() && descendant->get_parent() != this && descendant->data.owner != descendant->get_parent()) {
						hidden_roots.push_back(descendant);
					}
					continue;
				}
				node_tree.push_back(descendant);
				if (!descendant->get_scene_file_path().is_empty() && instance_roots.has(descendant->get_owner())) {
					instance_roots.push_back(descendant);
				}
			}