Repository: godot
Issue: Segfault in Node::get_path_to
Labels: bug,topic:core,crash

### Godot version

v4.2.beta.custom_build.d443f127e

### System information

Godot v4.2.beta (d443f127e) - Fedora Linux 39 (Workstation Edition) - X11 - Vulkan (Forward+) - integrated Intel(R) Xe Graphics (TGL GT2) () - 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz (8 Threads)

### Issue description

I had just stopped running the scene via the editor and then switched scene tabs and a segfault occurred.

```
(gdb) bt
#0  0x00007f4f28767834 in __pthread_kill_implementation () from /lib64/libc.so.6
#1  0x00007f4f287158ee in raise () from /lib64/libc.so.6
#2  0x00007f4f286fd8ff in abort () from /lib64/libc.so.6
#3  0x000000000384fb05 in handle_crash (sig=11) at platform/linuxbsd/crash_handler_linuxbsd.cpp:145
#4  <signal handler called>
#5  0x0000000005563004 in Node::get_path_to (this=0x288fbb70, p_node=0x2891c2c0, p_use_unique_path=false) at scene/main/node.cpp:2003
#6  0x0000000004973e78 in EditorData::check_and_update_scene (this=0xb6c9d48, p_idx=0) at editor/editor_data.cpp:708
#7  0x0000000004a83f1f in EditorNode::_set_current_scene_nocheck (this=0xb6c9920, p_idx=0) at editor/editor_node.cpp:3621
#8  0x0000000004a83dac in EditorNode::_set_current_scene (this=0xb6c9920, p_idx=0) at editor/editor_node.cpp:3612
#9  0x0000000004abda62 in call_with_variant_args_helper<EditorNode, int, 0ul> (p_instance=0xb6c9920, p_method=(void (EditorNode::*)(EditorNode * const, int)) 0x4a83d70 <EditorNode::_set_current_scene(int)>, 
    p_args=0x7ffe50094070, r_error=...) at ./core/variant/binder_common.h:303
#10 0x0000000004abc9db in call_with_variant_args<EditorNode, int> (p_instance=0xb6c9920, p_method=(void (EditorNode::*)(EditorNode * const, int)) 0x4a83d70 <EditorNode::_set_current_scene(int)>, 
    p_args=0x7ffe50094070, p_argcount=1, r_error=...) at ./core/variant/binder_common.h:417
#11 0x0000000004aba520 in CallableCustomMethodPointer<EditorNode, int>::call (this=0xc896570, p_arguments=0x7ffe50094070, p_argcount=1, r_return_value=..., r_call_error=...)
    at ./core/object/callable_method_pointer.h:104
#12 0x00000000070e7a7f in Callable::callp (this=0x1d83c1b0, p_arguments=0x7ffe50094070, p_argcount=1, r_return_value=..., r_call_error=...) at core/variant/callable.cpp:57
#13 0x000000000740d032 in Object::emit_signalp (this=0xc86eb90, p_name=..., p_args=0x7ffe50094070, p_argcount=1) at core/object/object.cpp:1127
#14 0x0000000005573672 in Node::emit_signalp (this=0xc86eb90, p_name=..., p_args=0x7ffe50094070, p_argcount=1) at scene/main/node.cpp:3606
#15 0x0000000003b3a7a1 in Object::emit_signal<int> (this=0xc86eb90, p_name=...) at ./core/object/object.h:922
#16 0x0000000004e3efe9 in EditorSceneTabs::_scene_tab_changed (this=0xc86eb90, p_tab=0) at editor/gui/editor_scene_tabs.cpp:72
#17 0x0000000004e44434 in call_with_variant_args_helper<EditorSceneTabs, int, 0ul> (p_instance=0xc86eb90, 
    p_method=(void (EditorSceneTabs::*)(EditorSceneTabs * const, int)) 0x4e3ef9a <EditorSceneTabs::_scene_tab_changed(int)>, p_args=0x7ffe500945e0, r_error=...) at ./core/variant/binder_common.h:303
#18 0x0000000004e44116 in call_with_variant_args<EditorSceneTabs, int> (p_instance=0xc86eb90, 
    p_method=(void (EditorSceneTabs::*)(EditorSceneTabs * const, int)) 0x4e3ef9a <EditorSceneTabs::_scene_tab_changed(int)>, p_args=0x7ffe500945e0, p_argcount=1, r_error=...) at ./core/variant/binder_common.h:417
#19 0x0000000004e43e86 in CallableCustomMethodPointer<EditorSceneTabs, int>::call (this=0x7f4ed4015030, p_arguments=0x7ffe500945e0, p_argcount=1, r_return_value=..., r_call_error=...)
    at ./core/object/callable_method_pointer.h:104
#20 0x00000000070e7a7f in Callable::callp (this=0x7f4ed401fc20, p_arguments=0x7ffe500945e0, p_argcount=1, r_return_value=..., r_call_error=...) at core/variant/callable.cpp:57
#21 0x000000000740d032 in Object::emit_signalp (this=0xc873140, p_name=..., p_args=0x7ffe500945e0, p_argcount=1) at core/object/object.cpp:1127
#22 0x0000000005573672 in Node::emit_signalp (this=0xc873140, p_name=..., p_args=0x7ffe500945e0, p_argcount=1) at scene/main/node.cpp:3606
#23 0x0000000003b3a7a1 in Object::emit_signal<int> (this=0xc873140, p_name=...) at ./core/object/object.h:922
#24 0x00000000058bedf1 in TabBar::set_current_tab (this=0xc873140, p_current=0) at scene/gui/tab_bar.cpp:656
#25 0x00000000058bbed4 in TabBar::gui_input (this=0xc873140, p_event=...) at scene/gui/tab_bar.cpp:282
#26 0x00000000056e3aff in Control::_call_gui_input (this=0xc873140, p_event=...) at scene/gui/control.cpp:1810
#27 0x00000000055c036f in Viewport::_gui_call_input (this=0xb659230, p_control=0xc873140, p_input=...) at scene/main/viewport.cpp:1593
#28 0x00000000055c127a in Viewport::_gui_input_event (this=0xb659230, p_event=...) at scene/main/viewport.cpp:1825
#29 0x00000000055c9b6e in Viewport::push_input (this=0xb659230, p_event=..., p_local_coords=false) at scene/main/viewport.cpp:3324
#30 0x0000000005609459 in Window::_window_input (this=0xb659230, p_ev=...) at scene/main/window.cpp:1551
#31 0x0000000005639535 in call_with_variant_args_helper<Window, Ref<InputEvent> const&, 0ul> (p_instance=0xb659230, 
    p_method=(void (Window::*)(Window * const, const Ref<InputEvent> &)) 0x560902c <Window::_window_input(Ref<InputEvent> const&)>, p_args=0x7ffe50097660, r_error=...) at ./core/variant/binder_common.h:303
#32 0x0000000005634e20 in call_with_variant_args<Window, Ref<InputEvent> const&> (p_instance=0xb659230, 
    p_method=(void (Window::*)(Window * const, const Ref<InputEvent> &)) 0x560902c <Window::_window_input(Ref<InputEvent> const&)>, p_args=0x7ffe50097660, p_argcount=1, r_error=...)
    at ./core/variant/binder_common.h:417
#33 0x000000000562fcc4 in CallableCustomMethodPointer<Window, Ref<InputEvent> const&>::call (this=0x1b0722e0, p_arguments=0x7ffe50097660, p_argcount=1, r_return_value=..., r_call_error=...)
    at ./core/object/callable_method_pointer.h:104
#34 0x00000000070e7a7f in Callable::callp (this=0x7ffe500976f0, p_arguments=0x7ffe50097660, p_argcount=1, r_return_value=..., r_call_error=...) at core/variant/callable.cpp:57
#35 0x00000000038853a7 in Callable::call<Ref<InputEvent> > (this=0x7ffe500976f0) at ./core/variant/variant.h:846
#36 0x000000000387b3dd in DisplayServerX11::_dispatch_input_event (this=0x8eaa790, p_event=...) at platform/linuxbsd/x11/display_server_x11.cpp:4001
#37 0x000000000387b167 in DisplayServerX11::_dispatch_input_events (p_event=...) at platform/linuxbsd/x11/display_server_x11.cpp:3977
#38 0x0000000007090fdc in Input::_parse_input_event_impl (this=0x87ac070, p_event=..., p_is_emulated=false) at core/input/input.cpp:730
#39 0x00000000070921d0 in Input::flush_buffered_events (this=0x87ac070) at core/input/input.cpp:994
#40 0x000000000387fefc in DisplayServerX11::process_events (this=0x8eaa790) at platform/linuxbsd/x11/display_server_x11.cpp:5071
#41 0x0000000003856718 in OS_LinuxBSD::run (this=0x7ffe50098050) at platform/linuxbsd/os_linuxbsd.cpp:929
#42 0x000000000384f01a in main (argc=4, argv=0x7ffe50098648) at platform/linuxbsd/godot_linuxbsd.cpp:74
(gdb) frame 5
#5  0x0000000005563004 in Node::get_path_to (this=0x288fbb70, p_node=0x2891c2c0, p_use_unique_path=false) at scene/main/node.cpp:2003
2003			common_parent = common_parent->data.parent;
(gdb) p common_parent 
$1 = (const Node *) 0x551
(gdb) p *common_parent 
Cannot access memory at address 0x551
(gdb) list
1998	
1999		while (common_parent) {
2000			if (visited.has(common_parent)) {
2001				break;
2002			}
2003			common_parent = common_parent->data.parent;
2004		}
2005	
2006		ERR_FAIL_NULL_V(common_parent, NodePath()); //nodes not in the same tree
2007
```

### Steps to reproduce

I haven't been able to reproduce it but hopefully the backtrace will be enough to pin the issue down.

### Minimal reproduction project

(No MRP)