### Godot version

v4.0.beta17.official [c40020513]

### System information

Linux mint 21, NVIDIA GeForce GTX 1050 Ti, Vulkan API 1.3.205

### Issue description

This is easy to reproduce in beta17, beta16 does not seem to have this issue.

~~This was discovered while trying to reproduce #72707, so may be related to #72707. But this issue can be reproduced under both i3wm and Cinnamon.~~

https://user-images.githubusercontent.com/30386067/216828188-20946fd9-b1f8-4c60-927e-b8afdd6f4931.mp4

<details> <summary>Click button</summary>

```
================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.0.beta.custom_build (00302860541e9cccc59abd93b930af2a6e6ec360)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] /lib/x86_64-linux-gnu/libc.so.6(+0x42520) [0x7f5cba6cc520] (??:0)
[2] HashMap<StringName, SpriteFrames::Anim, HashMapHasherDefault, HashMapComparatorDefault<StringName>, DefaultTypedAllocator<HashMapElement<StringName, SpriteFrames::Anim> > >::_lookup_pos(StringName const&, unsigned int&) const (/opt/godot/godot/./core/templates/hash_map.h:100)
[3] HashMap<StringName, SpriteFrames::Anim, HashMapHasherDefault, HashMapComparatorDefault<StringName>, DefaultTypedAllocator<HashMapElement<StringName, SpriteFrames::Anim> > >::has(StringName const&) const (/opt/godot/godot/./core/templates/hash_map.h:310)
[4] SpriteFrames::has_animation(StringName const&) const (/opt/godot/godot/scene/resources/sprite_frames.cpp:106)
[5] SpriteFramesEditor::_animation_add() (/opt/godot/godot/editor/plugins/sprite_frames_editor_plugin.cpp:866)
[6] void call_with_variant_args_helper<SpriteFramesEditor>(SpriteFramesEditor*, void (SpriteFramesEditor::*)(), Variant const**, Callable::CallError&, IndexSequence<>) (/opt/godot/godot/./core/variant/binder_common.h:298)
[7] void call_with_variant_args<SpriteFramesEditor>(SpriteFramesEditor*, void (SpriteFramesEditor::*)(), Variant const**, int, Callable::CallError&) (/opt/godot/godot/./core/variant/binder_common.h:408)
[8] CallableCustomMethodPointer<SpriteFramesEditor>::call(Variant const**, int, Variant&, Callable::CallError&) const (/opt/godot/godot/./core/object/callable_method_pointer.h:105)
[9] Callable::callp(Variant const**, int, Variant&, Callable::CallError&) const (/opt/godot/godot/core/variant/callable.cpp:51)
[10] Object::emit_signalp(StringName const&, Variant const**, int) (/opt/godot/godot/core/object/object.cpp:1046)
[11] Error Object::emit_signal<>(StringName const&) (/opt/godot/godot/./core/object/object.h:869)
[12] BaseButton::_pressed() (/opt/godot/godot/scene/gui/base_button.cpp:139)
[13] BaseButton::on_action_event(Ref<InputEvent>) (??:?)
[14] BaseButton::gui_input(Ref<InputEvent> const&) (/opt/godot/godot/scene/gui/base_button.cpp:69)
[15] Control::_call_gui_input(Ref<InputEvent> const&) (/opt/godot/godot/scene/gui/control.cpp:1745)
[16] Viewport::_gui_call_input(Control*, Ref<InputEvent> const&) (/opt/godot/godot/scene/main/viewport.cpp:1345)
[17] Viewport::_gui_input_event(Ref<InputEvent>) (/opt/godot/godot/scene/main/viewport.cpp:1615)
[18] Viewport::push_input(Ref<InputEvent> const&, bool) (/opt/godot/godot/scene/main/viewport.cpp:2793)
[19] Window::_window_input(Ref<InputEvent> const&) (/opt/godot/godot/scene/main/window.cpp:1350)
[20] void call_with_variant_args_helper<Window, Ref<InputEvent> const&, 0ul>(Window*, void (Window::*)(Ref<InputEvent> const&), Variant const**, Callable::CallError&, IndexSequence<0ul>) (/opt/godot/godot/./core/variant/binder_common.h:293)
[21] void call_with_variant_args<Window, Ref<InputEvent> const&>(Window*, void (Window::*)(Ref<InputEvent> const&), Variant const**, int, Callable::CallError&) (/opt/godot/godot/./core/variant/binder_common.h:408)
[22] CallableCustomMethodPointer<Window, Ref<InputEvent> const&>::call(Variant const**, int, Variant&, Callable::CallError&) const (/opt/godot/godot/./core/object/callable_method_pointer.h:105)
[23] Callable::callp(Variant const**, int, Variant&, Callable::CallError&) const (/opt/godot/godot/core/variant/callable.cpp:51)
[24] DisplayServerX11::_dispatch_input_event(Ref<InputEvent> const&) (/opt/godot/godot/platform/linuxbsd/x11/display_server_x11.cpp:3546)
[25] DisplayServerX11::_dispatch_input_events(Ref<InputEvent> const&) (/opt/godot/godot/platform/linuxbsd/x11/display_server_x11.cpp:3518)
[26] Input::_parse_input_event_impl(Ref<InputEvent> const&, bool) (/opt/godot/godot/core/input/input.cpp:685)
[27] Input::flush_buffered_events() (/opt/godot/godot/core/input/input.cpp:934)
[28] DisplayServerX11::process_events() (/opt/godot/godot/platform/linuxbsd/x11/display_server_x11.cpp:4615)
[29] OS_LinuxBSD::run() (/opt/godot/godot/platform/linuxbsd/os_linuxbsd.cpp:876)
[30] /opt/godot/godot/bin/godot.linuxbsd.editor.dev.x86_64.llvm(main+0x1fe) [0x564ee370782e] (/opt/godot/godot/platform/linuxbsd/godot_linuxbsd.cpp:73)
[31] /lib/x86_64-linux-gnu/libc.so.6(+0x29d90) [0x7f5cba6b3d90] (??:0)
[32] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x7f5cba6b3e40] (??:0)
[33] /opt/godot/godot/bin/godot.linuxbsd.editor.dev.x86_64.llvm(_start+0x25) [0x564ee3707565] (??:?)
-- END OF BACKTRACE --
================================================================
```
</details>

https://user-images.githubusercontent.com/30386067/216828183-b0979176-2166-47da-96c0-b16908515d78.mp4

<details> <summary>Click name</summary>

```
================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.0.beta.custom_build (00302860541e9cccc59abd93b930af2a6e6ec360)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] /lib/x86_64-linux-gnu/libc.so.6(+0x42520) [0x7f469b1ba520] (??:0)
[2] HashMap<StringName, SpriteFrames::Anim, HashMapHasherDefault, HashMapComparatorDefault<StringName>, DefaultTypedAllocator<HashMapElement<StringName, SpriteFrames::Anim> > >::_lookup_pos(StringName const&, unsigned int&) const (/opt/godot/godot/./core/templates/hash_map.h:100)
[3] HashMap<StringName, SpriteFrames::Anim, HashMapHasherDefault, HashMapComparatorDefault<StringName>, DefaultTypedAllocator<HashMapElement<StringName, SpriteFrames::Anim> > >::has(StringName const&) const (/opt/godot/godot/./core/templates/hash_map.h:310)
[4] SpriteFrames::has_animation(StringName const&) const (/opt/godot/godot/scene/resources/sprite_frames.cpp:106)
[5] SpriteFramesEditor::_animation_selected() (/opt/godot/godot/editor/plugins/sprite_frames_editor_plugin.cpp:716)
[6] void call_with_variant_args_helper<SpriteFramesEditor>(SpriteFramesEditor*, void (SpriteFramesEditor::*)(), Variant const**, Callable::CallError&, IndexSequence<>) (/opt/godot/godot/./core/variant/binder_common.h:298)
[7] void call_with_variant_args<SpriteFramesEditor>(SpriteFramesEditor*, void (SpriteFramesEditor::*)(), Variant const**, int, Callable::CallError&) (/opt/godot/godot/./core/variant/binder_common.h:408)
[8] CallableCustomMethodPointer<SpriteFramesEditor>::call(Variant const**, int, Variant&, Callable::CallError&) const (/opt/godot/godot/./core/object/callable_method_pointer.h:105)
[9] Callable::callp(Variant const**, int, Variant&, Callable::CallError&) const (/opt/godot/godot/core/variant/callable.cpp:51)
[10] Object::emit_signalp(StringName const&, Variant const**, int) (/opt/godot/godot/core/object/object.cpp:1046)
[11] Error Object::emit_signal<>(StringName const&) (/opt/godot/godot/./core/object/object.h:869)
[12] Tree::select_single_item(TreeItem*, TreeItem*, int, TreeItem*, bool*, bool) (/opt/godot/godot/scene/gui/tree.cpp:2516)
[13] Tree::select_single_item(TreeItem*, TreeItem*, int, TreeItem*, bool*, bool) (/opt/godot/godot/scene/gui/tree.cpp:2554)
[14] Tree::propagate_mouse_event(Vector2i const&, int, int, int, bool, TreeItem*, MouseButton, Ref<InputEventWithModifiers> const&) (??:?)
[15] Tree::propagate_mouse_event(Vector2i const&, int, int, int, bool, TreeItem*, MouseButton, Ref<InputEventWithModifiers> const&) (/opt/godot/godot/scene/gui/tree.cpp:2944)
[16] Tree::gui_input(Ref<InputEvent> const&) (/opt/godot/godot/scene/gui/tree.cpp:3649)
[17] Control::_call_gui_input(Ref<InputEvent> const&) (/opt/godot/godot/scene/gui/control.cpp:1745)
[18] Viewport::_gui_call_input(Control*, Ref<InputEvent> const&) (/opt/godot/godot/scene/main/viewport.cpp:1345)
[19] Viewport::_gui_input_event(Ref<InputEvent>) (/opt/godot/godot/scene/main/viewport.cpp:1574)
[20] Viewport::push_input(Ref<InputEvent> const&, bool) (/opt/godot/godot/scene/main/viewport.cpp:2793)
[21] Window::_window_input(Ref<InputEvent> const&) (/opt/godot/godot/scene/main/window.cpp:1350)
[22] void call_with_variant_args_helper<Window, Ref<InputEvent> const&, 0ul>(Window*, void (Window::*)(Ref<InputEvent> const&), Variant const**, Callable::CallError&, IndexSequence<0ul>) (/opt/godot/godot/./core/variant/binder_common.h:293)
[23] void call_with_variant_args<Window, Ref<InputEvent> const&>(Window*, void (Window::*)(Ref<InputEvent> const&), Variant const**, int, Callable::CallError&) (/opt/godot/godot/./core/variant/binder_common.h:408)
[24] CallableCustomMethodPointer<Window, Ref<InputEvent> const&>::call(Variant const**, int, Variant&, Callable::CallError&) const (/opt/godot/godot/./core/object/callable_method_pointer.h:105)
[25] Callable::callp(Variant const**, int, Variant&, Callable::CallError&) const (/opt/godot/godot/core/variant/callable.cpp:51)
[26] DisplayServerX11::_dispatch_input_event(Ref<InputEvent> const&) (/opt/godot/godot/platform/linuxbsd/x11/display_server_x11.cpp:3546)
[27] DisplayServerX11::_dispatch_input_events(Ref<InputEvent> const&) (/opt/godot/godot/platform/linuxbsd/x11/display_server_x11.cpp:3518)
[28] Input::_parse_input_event_impl(Ref<InputEvent> const&, bool) (/opt/godot/godot/core/input/input.cpp:685)
[29] Input::flush_buffered_events() (/opt/godot/godot/core/input/input.cpp:934)
[30] DisplayServerX11::process_events() (/opt/godot/godot/platform/linuxbsd/x11/display_server_x11.cpp:4615)
[31] OS_LinuxBSD::run() (/opt/godot/godot/platform/linuxbsd/os_linuxbsd.cpp:876)
[32] /opt/godot/godot/bin/godot.linuxbsd.editor.dev.x86_64.llvm(main+0x1fe) [0x556d7c23182e] (/opt/godot/godot/platform/linuxbsd/godot_linuxbsd.cpp:73)
[33] /lib/x86_64-linux-gnu/libc.so.6(+0x29d90) [0x7f469b1a1d90] (??:0)
[34] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x7f469b1a1e40] (??:0)
[35] /opt/godot/godot/bin/godot.linuxbsd.editor.dev.x86_64.llvm(_start+0x25) [0x556d7c231565] (??:?)
-- END OF BACKTRACE --
================================================================
```
</details>




### Steps to reproduce

1. Open the MRP in the editor;
2. Open node_2d.tscn;
3. Click AnimatedSprite2D to open the SpriteFrames bottom panel;
4. Double-click on the Scene dock, and then try to click the Add animation button or click the name of an animation;
5. May crash.

### Minimal reproduction project

[click-crash.zip](https://github.com/godotengine/godot/files/10611407/click-crash.zip)

ERR_FAIL_COND(!frames->has_animation(edited_anim));
	List<Ref<Textre2D>> resorces;
	for (int i = 0; i < p_path.size(); i++) {
		Ref<Textre2D> resorce;
		resorce = ResorceLoader::load(p_path[i]);
		if (resorce.is_nll()) {
			dialog->set_text(TTR("ERROR: Coldn't load frame resorce!"));
			dialog->set_title(TTR("Error!"));
			
			dialog->set_ok_btton_text(TTR("Close"));
			dialog->popp_centered();
			retrn; 
		}
		resorces.psh_back(resorce);
	}
	if (resorces.is_empty()) {
		retrn;
	}
	EditorUndoRedoManager *ndo_redo = EditorUndoRedoManager::get_singleton();
	ndo_redo->create_action(TTR("Add Frame"), UndoRedo::MERGE_DISABLE, EditorNode::get_singleton()->get_edited_scene());
	int fc = frames->get_frame_cont(edited_anim);
	int cont = 0;
	for (const Ref<Textre2D> &E : resorces) {
		ndo_redo->add_do_method(frames.ptr(), "add_frame", edited_anim, E, 1.0, p_at_pos == -1 ? -1 : p_at_pos + cont);
		ndo_redo->add_ndo_method(frames.ptr(), "remove_frame", edited_anim, p_at_pos == -1 ? fc : p_at_pos);
		cont++;