Repository: godot
Issue: Freeze when closing editor with big amount of resources
Labels: bug,topic:editor,confirmed,crash

### Godot version

3.4.beta.custom_build. 01ae4888e

### System information

Ubuntu 21.10 - Nvidia GTX 970, Gnome shell 40.4 X11

### Issue description

When trying to close editor with a lot of resources, it freeze and must be killed manually.
```
(gdb) backtrace
#0  0x00007ffff7b6ca48 in __GI___clock_nanosleep (clock_id=clock_id@entry=0, flags=flags@entry=0, req=0x7fffffffbbc0, rem=0x7fffffffbbd0) at ../sysdeps/unix/sysv/linux/clock_nanosleep.c:78
#1  0x00007ffff7b71957 in __GI___nanosleep (req=<optimized out>, rem=<optimized out>) at ../sysdeps/unix/sysv/linux/nanosleep.c:25
#2  0x00000000029d3942 in OS_Unix::delay_usec (this=0x7fffffffd580, p_usec=10000) at drivers/unix/os_unix.cpp:243
#3  0x0000000002d6a943 in EditorResourcePreview::stop (this=0xb5b55c0) at editor/editor_resource_preview.cpp:441
#4  0x0000000002c89448 in EditorNode::_exit_editor (this=0xb16b890) at editor/editor_node.cpp:2926
#5  0x0000000002c89827 in EditorNode::_discard_changes (this=0xb16b890, p_str=...) at editor/editor_node.cpp:2982
#6  0x0000000002c85741 in EditorNode::_menu_option_confirm (this=0xb16b890, p_option=27, p_confirmed=true) at editor/editor_node.cpp:2704
#7  0x0000000002c7710d in EditorNode::_menu_confirm_current (this=0xb16b890) at editor/editor_node.cpp:1108
#8  0x00000000018685a7 in MethodBind0::call (this=0x11162840, p_object=0xb16b890, p_args=0x7fffffffc180, p_arg_count=0, r_error=...) at ./core/method_bind.gen.inc:59
#9  0x000000000477623c in Object::call (this=0xb16b890, p_method=..., p_args=0x7fffffffc180, p_argcount=0, r_error=...) at core/object.cpp:918
#10 0x0000000004778313 in Object::emit_signal (this=0xda334a0, p_name=..., p_args=0x7fffffffc180, p_argcount=0) at core/object.cpp:1224
#11 0x0000000004778a7e in Object::emit_signal (this=0xda334a0, p_name=..., p_arg1=..., p_arg2=..., p_arg3=..., p_arg4=..., p_arg5=...) at core/object.cpp:1279
#12 0x000000000382c1a3 in AcceptDialog::_ok_pressed (this=0xda334a0) at scene/gui/dialogs.cpp:398
#13 0x00000000018685a7 in MethodBind0::call (this=0x9b45500, p_object=0xda334a0, p_args=0x7fffffffc560, p_arg_count=0, r_error=...) at ./core/method_bind.gen.inc:59
#14 0x000000000477623c in Object::call (this=0xda334a0, p_method=..., p_args=0x7fffffffc560, p_argcount=0, r_error=...) at core/object.cpp:918
#15 0x0000000004778313 in Object::emit_signal (this=0xda36250, p_name=..., p_args=0x7fffffffc560, p_argcount=0) at core/object.cpp:1224
#16 0x0000000004778a7e in Object::emit_signal (this=0xda36250, p_name=..., p_arg1=..., p_arg2=..., p_arg3=..., p_arg4=..., p_arg5=...) at core/object.cpp:1279
#17 0x00000000037ba639 in BaseButton::_pressed (this=0xda36250) at scene/gui/base_button.cpp:128
#18 0x00000000037baf53 in BaseButton::on_action_event (this=0xda36250, p_event=...) at scene/gui/base_button.cpp:163
#19 0x00000000037ba196 in BaseButton::_gui_input (this=0xda36250, p_event=...) at scene/gui/base_button.cpp:67
#20 0x0000000002e10a0a in MethodBind1<Ref<InputEvent> >::call (this=0x9aef820, p_object=0xda36250, p_args=0x7fffffffc980, p_arg_count=1, r_error=...) at ./core/method_bind.gen.inc:775
#21 0x000000000477558d in Object::call_multilevel (this=0xda36250, p_method=..., p_args=0x7fffffffc980, p_argcount=1) at core/object.cpp:766
#22 0x0000000004775e70 in Object::call_multilevel (this=0xda36250, p_name=..., p_arg1=..., p_arg2=..., p_arg3=..., p_arg4=..., p_arg5=...) at core/object.cpp:863
#23 0x0000000003787c50 in Viewport::_gui_call_input (this=0xa249160, p_control=0xda36250, p_input=...) at scene/main/viewport.cpp:1652
#24 0x00000000037894f1 in Viewport::_gui_input_event (this=0xa249160, p_event=...) at scene/main/viewport.cpp:2038
#25 0x000000000378dd68 in Viewport::input (this=0xa249160, p_event=...) at scene/main/viewport.cpp:2803
#26 0x000000000378687b in Viewport::_vp_input (this=0xa249160, p_ev=...) at scene/main/viewport.cpp:1421
#27 0x0000000001aef1c6 in MethodBind1<Ref<InputEvent> const&>::call (this=0x9cb1690, p_object=0xa249160, p_args=0x7fffffffcfa0, p_arg_count=1, r_error=...) at ./core/method_bind.gen.inc:775
#28 0x000000000477623c in Object::call (this=0xa249160, p_method=..., p_args=0x7fffffffcfa0, p_argcount=1, r_error=...) at core/object.cpp:918
#29 0x0000000004775d93 in Object::call (this=0xa249160, p_name=..., p_arg1=..., p_arg2=..., p_arg3=..., p_arg4=..., p_arg5=...) at core/object.cpp:847
#30 0x00000000037567ca in SceneTree::call_group_flags (this=0x9fe4100, p_call_flags=2, p_group=..., p_function=..., p_arg1=..., p_arg2=..., p_arg3=..., p_arg4=..., p_arg5=...) at scene/main/scene_tree.cpp:272
#31 0x0000000003757564 in SceneTree::input_event (this=0x9fe4100, p_event=...) at scene/main/scene_tree.cpp:431
#32 0x00000000017c417f in InputDefault::_parse_input_event_impl (this=0x6fa9a20, p_event=..., p_is_emulated=false) at main/input_default.cpp:477
#33 0x00000000017c57b6 in InputDefault::flush_buffered_events (this=0x6fa9a20) at main/input_default.cpp:698
#34 0x00000000017a5599 in OS_X11::process_xevents (this=0x7fffffffd580) at platform/x11/os_x11.cpp:2908
#35 0x00000000017a9a9b in OS_X11::run (this=0x7fffffffd580) at platform/x11/os_x11.cpp:3637
#36 0x00000000017962f7 in main (argc=2, argv=0x7fffffffdea8) at platform/x11/godot_x11.cpp:55
```

### Steps to reproduce

Open project in editor
Try to close it

### Minimal reproduction project

[test_resources.zip](https://github.com/godotengine/godot/files/7447203/test_resources.zip)