### Godot version

4.2 3fa8fad

### System information

Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1060 (NVIDIA; 30.0.15.1403) - Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz (8 Threads)

### Issue description

```
CrashHandlerException: Program crashed
Engine version: Godot Engine v4.2.dev.custom_build (3fa8fad26b97a8af20e7996b7e17d8f23fc04b89)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[0] SafeRefCount::_check_unref_sanity (C:\godot_source\core\templates\safe_refcount.h:187)
[1] SafeRefCount::unrefval (C:\godot_source\core\templates\safe_refcount.h:214)
[2] RefCounted::unreference (C:\godot_source\core\object\ref_counted.cpp:77)
[3] Ref<TileSet>::unref (C:\godot_source\core\object\ref_counted.h:209)
[4] Ref<TileSet>::ref (C:\godot_source\core\object\ref_counted.h:67)
[5] Ref<TileSet>::operator= (C:\godot_source\core\object\ref_counted.h:118)
[6] TileSetAtlasSourceEditor::_tile_set_changed (C:\godot_source\editor\plugins\tiles\tile_set_atlas_source_editor.cpp:2085)
[7] call_with_variant_args_helper<TileSetAtlasSourceEditor> (C:\godot_source\core\variant\binder_common.h:308)
[8] call_with_variant_args<TileSetAtlasSourceEditor> (C:\godot_source\core\variant\binder_common.h:418)
[9] CallableCustomMethodPointer<TileSetAtlasSourceEditor>::call (C:\godot_source\core\object\callable_method_pointer.h:105)
[10] Callable::callp (C:\godot_source\core\variant\callable.cpp:51)
[11] Object::emit_signalp (C:\godot_source\core\object\object.cpp:1073)
[12] Object::emit_signal<> (C:\godot_source\core\object\object.h:891)
[13] Resource::emit_changed (C:\godot_source\core\io\resource.cpp:45)
[14] TileSet::remove_source (C:\godot_source\scene\resources\tile_set.cpp:510)
[15] TileSet::~TileSet (C:\godot_source\scene\resources\tile_set.cpp:3602)
[16] TileSet::`scalar deleting destructor'
[17] memdelete<TileSet> (C:\godot_source\core\os\memory.h:112)
[18] Ref<TileSet>::unref (C:\godot_source\core\object\ref_counted.h:212)
[19] Ref<TileSet>::~Ref<TileSet> (C:\godot_source\core\object\ref_counted.h:222)
[20] TileSetAtlasSourceEditor::~TileSetAtlasSourceEditor (C:\godot_source\editor\plugins\tiles\tile_set_atlas_source_editor.cpp:2657)
[21] TileSetAtlasSourceEditor::`scalar deleting destructor'
[22] memdelete<Node> (C:\godot_source\core\os\memory.h:112)
[23] Node::_notification (C:\godot_source\scene\main\node.cpp:212)
[24] Node::_notificationv (C:\godot_source\scene\main\node.h:49)
[25] CanvasItem::_notificationv (C:\godot_source\scene\main\canvas_item.h:45)
[26] Control::_notificationv (C:\godot_source\scene\gui\control.h:47)
[27] Container::_notificationv (C:\godot_source\scene\gui\container.h:37)
[28] BoxContainer::_notificationv (C:\godot_source\scene\gui\box_container.h:37)
[29] VBoxContainer::_notificationv (C:\godot_source\scene\gui\box_container.h:92)
[30] Object::notification (C:\godot_source\core\object\object.cpp:800)
[31] Object::_predelete (C:\godot_source\core\object\object.cpp:198)
[32] predelete_handler (C:\godot_source\core\object\object.cpp:1893)
[33] memdelete<Node> (C:\godot_source\core\os\memory.h:105)
[34] Node::_notification (C:\godot_source\scene\main\node.cpp:212)
[35] Node::_notificationv (C:\godot_source\scene\main\node.h:49)
[36] CanvasItem::_notificationv (C:\godot_source\scene\main\canvas_item.h:45)
[37] Control::_notificationv (C:\godot_source\scene\gui\control.h:47)
[38] Container::_notificationv (C:\godot_source\scene\gui\container.h:37)
[39] SplitContainer::_notificationv (C:\godot_source\scene\gui\split_container.h:54)
[40] HSplitContainer::_notificationv (C:\godot_source\scene\gui\split_container.h:124)
[41] Object::notification (C:\godot_source\core\object\object.cpp:800)
[42] Object::_predelete (C:\godot_source\core\object\object.cpp:198)
[43] predelete_handler (C:\godot_source\core\object\object.cpp:1893)
[44] memdelete<Node> (C:\godot_source\core\os\memory.h:105)
[45] Node::_notification (C:\godot_source\scene\main\node.cpp:212)
[46] Node::_notificationv (C:\godot_source\scene\main\node.h:49)
[47] CanvasItem::_notificationv (C:\godot_source\scene\main\canvas_item.h:45)
[48] Control::_notificationv (C:\godot_source\scene\gui\control.h:47)
[49] Container::_notificationv (C:\godot_source\scene\gui\container.h:37)
[50] BoxContainer::_notificationv (C:\godot_source\scene\gui\box_container.h:37)
[51] VBoxContainer::_notificationv (C:\godot_source\scene\gui\box_container.h:92)
[52] Object::notification (C:\godot_source\core\object\object.cpp:800)
[53] Object::_predelete (C:\godot_source\core\object\object.cpp:198)
[54] predelete_handler (C:\godot_source\core\object\object.cpp:1893)
[55] memdelete<Node> (C:\godot_source\core\os\memory.h:105)
[56] Node::_notification (C:\godot_source\scene\main\node.cpp:212)
[57] Node::_notificationv (C:\godot_source\scene\main\node.h:49)
[58] CanvasItem::_notificationv (C:\godot_source\scene\main\canvas_item.h:45)
[59] Control::_notificationv (C:\godot_source\scene\gui\control.h:47)
[60] TileSetEditor::_notificationv (C:\godot_source\editor\plugins\tiles\tile_set_editor.h:46)
[61] Object::notification (C:\godot_source\core\object\object.cpp:800)
[62] Object::_predelete (C:\godot_source\core\object\object.cpp:198)
[63] predelete_handler (C:\godot_source\core\object\object.cpp:1893)
[64] memdelete<Node> (C:\godot_source\core\os\memory.h:105)
[65] Node::_notification (C:\godot_source\scene\main\node.cpp:212)
[66] Node::_notificationv (C:\godot_source\scene\main\node.h:49)
[67] CanvasItem::_notificationv (C:\godot_source\scene\main\canvas_item.h:45)
[68] Control::_notificationv (C:\godot_source\scene\gui\control.h:47)
[69] Container::_notificationv (C:\godot_source\scene\gui\container.h:37)
[70] BoxContainer::_notificationv (C:\godot_source\scene\gui\box_container.h:37)
[71] VBoxContainer::_notificationv (C:\godot_source\scene\gui\box_container.h:92)
[72] Object::notification (C:\godot_source\core\object\object.cpp:800)
[73] Object::_predelete (C:\godot_source\core\object\object.cpp:198)
[74] predelete_handler (C:\godot_source\core\object\object.cpp:1893)
[75] memdelete<Node> (C:\godot_source\core\os\memory.h:105)
[76] Node::_notification (C:\godot_source\scene\main\node.cpp:212)
[77] Node::_notificationv (C:\godot_source\scene\main\node.h:49)
[78] CanvasItem::_notificationv (C:\godot_source\scene\main\canvas_item.h:45)
[79] Control::_notificationv (C:\godot_source\scene\gui\control.h:47)
[80] Container::_notificationv (C:\godot_source\scene\gui\container.h:37)
[81] PanelContainer::_notificationv (C:\godot_source\scene\gui\panel_container.h:37)
[82] Object::notification (C:\godot_source\core\object\object.cpp:800)
[83] Object::_predelete (C:\godot_source\core\object\object.cpp:198)
[84] predelete_handler (C:\godot_source\core\object\object.cpp:1893)
[85] memdelete<Node> (C:\godot_source\core\os\memory.h:105)
[86] Node::_notification (C:\godot_source\scene\main\node.cpp:212)
[87] Node::_notificationv (C:\godot_source\scene\main\node.h:49)
[88] CanvasItem::_notificationv (C:\godot_source\scene\main\canvas_item.h:45)
[89] Control::_notificationv (C:\godot_source\scene\gui\control.h:47)
[90] Container::_notificationv (C:\godot_source\scene\gui\container.h:37)
[91] SplitContainer::_notificationv (C:\godot_source\scene\gui\split_container.h:54)
[92] VSplitContainer::_notificationv (C:\godot_source\scene\gui\split_container.h:132)
[93] Object::notification (C:\godot_source\core\object\object.cpp:800)
[94] Object::_predelete (C:\godot_source\core\object\object.cpp:198)
[95] predelete_handler (C:\godot_source\core\object\object.cpp:1893)
[96] memdelete<Node> (C:\godot_source\core\os\memory.h:105)
[97] Node::_notification (C:\godot_source\scene\main\node.cpp:212)
[98] Node::_notificationv (C:\godot_source\scene\main\node.h:49)
[99] CanvasItem::_notificationv (C:\godot_source\scene\main\canvas_item.h:45)
[100] Control::_notificationv (C:\godot_source\scene\gui\control.h:47)
[101] Container::_notificationv (C:\godot_source\scene\gui\container.h:37)
[102] BoxContainer::_notificationv (C:\godot_source\scene\gui\box_container.h:37)
[103] VBoxContainer::_notificationv (C:\godot_source\scene\gui\box_container.h:92)
[104] Object::notification (C:\godot_source\core\object\object.cpp:800)
[105] Object::_predelete (C:\godot_source\core\object\object.cpp:198)
[106] predelete_handler (C:\godot_source\core\object\object.cpp:1893)
[107] memdelete<Node> (C:\godot_source\core\os\memory.h:105)
[108] Node::_notification (C:\godot_source\scene\main\node.cpp:212)
[109] Node::_notificationv (C:\godot_source\scene\main\node.h:49)
[110] CanvasItem::_notificationv (C:\godot_source\scene\main\canvas_item.h:45)
[111] Control::_notificationv (C:\godot_source\scene\gui\control.h:47)
[112] Container::_notificationv (C:\godot_source\scene\gui\container.h:37)
[113] SplitContainer::_notificationv (C:\godot_source\scene\gui\split_container.h:54)
[114] HSplitContainer::_notificationv (C:\godot_source\scene\gui\split_container.h:124)
[115] Object::notification (C:\godot_source\core\object\object.cpp:800)
[116] Object::_predelete (C:\godot_source\core\object\object.cpp:198)
[117] predelete_handler (C:\godot_source\core\object\object.cpp:1893)
[118] memdelete<Node> (C:\godot_source\core\os\memory.h:105)
[119] Node::_notification (C:\godot_source\scene\main\node.cpp:212)
[120] Node::_notificationv (C:\godot_source\scene\main\node.h:49)
[121] CanvasItem::_notificationv (C:\godot_source\scene\main\canvas_item.h:45)
[122] Control::_notificationv (C:\godot_source\scene\gui\control.h:47)
[123] Container::_notificationv (C:\godot_source\scene\gui\container.h:37)
[124] SplitContainer::_notificationv (C:\godot_source\scene\gui\split_container.h:54)
[125] HSplitContainer::_notificationv (C:\godot_source\scene\gui\split_container.h:124)
[126] Object::notification (C:\godot_source\core\object\object.cpp:800)
[127] Object::_predelete (C:\godot_source\core\object\object.cpp:198)
[128] predelete_handler (C:\godot_source\core\object\object.cpp:1893)
[129] memdelete<Node> (C:\godot_source\core\os\memory.h:105)
[130] Node::_notification (C:\godot_source\scene\main\node.cpp:212)
[131] Node::_notificationv (C:\godot_source\scene\main\node.h:49)
[132] CanvasItem::_notificationv (C:\godot_source\scene\main\canvas_item.h:45)
[133] Control::_notificationv (C:\godot_source\scene\gui\control.h:47)
[134] Container::_notificationv (C:\godot_source\scene\gui\container.h:37)
[135] SplitContainer::_notificationv (C:\godot_source\scene\gui\split_container.h:54)
[136] HSplitContainer::_notificationv (C:\godot_source\scene\gui\split_container.h:124)
[137] Object::notification (C:\godot_source\core\object\object.cpp:800)
[138] Object::_predelete (C:\godot_source\core\object\object.cpp:198)
[139] predelete_handler (C:\godot_source\core\object\object.cpp:1893)
[140] memdelete<Node> (C:\godot_source\core\os\memory.h:105)
[141] Node::_notification (C:\godot_source\scene\main\node.cpp:212)
[142] Node::_notificationv (C:\godot_source\scene\main\node.h:49)
[143] CanvasItem::_notificationv (C:\godot_source\scene\main\canvas_item.h:45)
[144] Control::_notificationv (C:\godot_source\scene\gui\control.h:47)
[145] Container::_notificationv (C:\godot_source\scene\gui\container.h:37)
[146] BoxContainer::_notificationv (C:\godot_source\scene\gui\box_container.h:37)
[147] VBoxContainer::_notificationv (C:\godot_source\scene\gui\box_container.h:92)
[148] Object::notification (C:\godot_source\core\object\object.cpp:800)
[149] Object::_predelete (C:\godot_source\core\object\object.cpp:198)
[150] predelete_handler (C:\godot_source\core\object\object.cpp:1893)
[151] memdelete<Node> (C:\godot_source\core\os\memory.h:105)
[152] Node::_notification (C:\godot_source\scene\main\node.cpp:212)
[153] Node::_notificationv (C:\godot_source\scene\main\node.h:49)
[154] CanvasItem::_notificationv (C:\godot_source\scene\main\canvas_item.h:45)
[155] Control::_notificationv (C:\godot_source\scene\gui\control.h:47)
[156] Panel::_notificationv (C:\godot_source\scene\gui\panel.h:37)
[157] Object::notification (C:\godot_source\core\object\object.cpp:800)
[158] Object::_predelete (C:\godot_source\core\object\object.cpp:198)
[159] predelete_handler (C:\godot_source\core\object\object.cpp:1893)
[160] memdelete<Node> (C:\godot_source\core\os\memory.h:105)
[161] Node::_notification (C:\godot_source\scene\main\node.cpp:212)
[162] Node::_notificationv (C:\godot_source\scene\main\node.h:49)
[163] CanvasItem::_notificationv (C:\godot_source\scene\main\canvas_item.h:45)
[164] Control::_notificationv (C:\godot_source\scene\gui\control.h:47)
[165] Object::notification (C:\godot_source\core\object\object.cpp:800)
[166] Object::_predelete (C:\godot_source\core\object\object.cpp:198)
[167] predelete_handler (C:\godot_source\core\object\object.cpp:1893)
[168] memdelete<Node> (C:\godot_source\core\os\memory.h:105)
[169] Node::_notification (C:\godot_source\scene\main\node.cpp:212)
[170] Node::_notificationv (C:\godot_source\scene\main\node.h:49)
[171] EditorNode::_notificationv (C:\godot_source\editor\editor_node.h:118)
[172] Object::notification (C:\godot_source\core\object\object.cpp:800)
[173] Object::_predelete (C:\godot_source\core\object\object.cpp:198)
[174] predelete_handler (C:\godot_source\core\object\object.cpp:1893)
[175] memdelete<Node> (C:\godot_source\core\os\memory.h:105)
[176] Node::_notification (C:\godot_source\scene\main\node.cpp:212)
[177] Node::_notificationv (C:\godot_source\scene\main\node.h:49)
[178] Viewport::_notificationv (C:\godot_source\scene\main\viewport.h:93)
[179] Window::_notificationv (C:\godot_source\scene\main\window.h:44)
[180] Object::notification (C:\godot_source\core\object\object.cpp:800)
[181] Object::_predelete (C:\godot_source\core\object\object.cpp:198)
[182] predelete_handler (C:\godot_source\core\object\object.cpp:1893)
[183] memdelete<Window> (C:\godot_source\core\os\memory.h:105)
[184] SceneTree::finalize (C:\godot_source\scene\main\scene_tree.cpp:629)
[185] OS_Windows::run (C:\godot_source\platform\windows\os_windows.cpp:1485)
[186] widechar_main (C:\godot_source\platform\windows\godot_windows.cpp:182)
[187] _main (C:\godot_source\platform\windows\godot_windows.cpp:204)
[188] main (C:\godot_source\platform\windows\godot_windows.cpp:218)
[189] WinMain (C:\godot_source\platform\windows\godot_windows.cpp:232)
[190] __scrt_common_main_seh (D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
[191] <couldn't map PC to fn name>
-- END OF BACKTRACE --
```

### Steps to reproduce

1. Open the MRP
2. Open the scene
3. Click the TileMap node
4. Unfold the TileSet in the inspector
5. Click empty space in scene tree to deselect TileMap
6. Exit the editor

### Minimal reproduction project

[tilemap.zip](https://github.com/godotengine/godot/files/12309356/tilemap.zip)
drag_type = DRAG_TYPE_CREATE_BIG_TILE;
									drag_start_mouse_pos = mouse_local_pos;
									drag_last_mouse_pos = drag_start_mouse_pos;
									drag_current_tile = coords;
									
									tile_set_atlas_source->create_tile(coords);
								}
							} else if (mb->is_ctrl_pressed()) {
								
								drag_type = DRAG_TYPE_CREATE_TILES_USING_RECT;
								drag_start_mouse_pos = mouse_local_pos;
								drag_last_mouse_pos = drag_start_mouse_pos;
							} else {
								
								
								drag_type = DRAG_TYPE_CREATE_TILES;
								drag_start_mouse_pos = mouse_local_pos;
								drag_last_mouse_pos = drag_start_mouse_pos;
								
								Vector2i coords = tile_atlas_view->get_atlas_tile_coords_at_pos(drag_start_mouse_pos);
								if (coords != TileSetSource::INVALID_ATLAS_COORDS && tile_set_atlas_source->get_tile_at_coords(coords) == TileSetSource::INVALID_ATLAS_COORDS) {
									tile_set_atlas_source->create_tile(coords);
									drag_modified_tiles.insert(coords);
								}
							}
						}
					} else if (tools_button_group->get_pressed_button() == tool_select_button) {
						
						drag_type = DRAG_TYPE_NONE;