### 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.
bool is_detected = false;
		while (n != common_parent) {
			if (n->is_unique_name_in_owner() && n->get_owner() == get_owner()) {
				path.push_back(UNIQUE_NODE_PREFIX + String(n->get_name()));
				is_detected = true;
				break;
			}
			path.push_back(n->get_name());
			n = n->data.parent;
		}
		if (!is_detected) {
			n = this;
			String detected_name;
			int up_count = 0;
			while (n != common_parent) {
				if (n->is_unique_name_in_owner() && n->get_owner() == get_owner()) {
					detected_name = n->get_name();
					up_count = 0;
				}
				up_count++;
				n = n->data.parent;
			}
			for (int i = 0; i < up_count; i++) {
				path.push_back(up);
			}
			if (!detected_name.is_empty()) {
				path.push_back(UNIQUE_NODE_PREFIX + detected_name);
			}
		}
	} else {