### Godot version

4.1 Stable 

### System information

Windows 11, Intel(R) Core(TM) i5-10400F CPU, NVIDIA GeForce GTX 1060 6GB, 24 ram

### Issue description

When deleting Terrains in the tileset resource, on terrain sets, then going on terrains on the tilemap editor, on the tilemap tab, it crashes for some reason, it even happens eventually if you delete the Tile images under the TileSet Tab before you delete the terrains under terrain sets.

### Steps to reproduce

1. Drag and drop my tilemap packed scene onto the overworld scene.
2. Make the packed scene local, then make the tileset resource unique.
3. Delete those Terrains in the tileset resource, on terrain sets.
4. Go on terrains on the tilemap editor, on the tilemap tab. If it doesnt crash at first, switch back to the tileset tab and then go back to the tilemap tab and in the terrains section.

### Minimal reproduction project

[BreezeVillage.zip](https://github.com/godotengine/godot/files/12069715/BreezeVillage.zip)

ERR_FAIL_COND_V_MSG(!tiles.has(p_atlas_coords), TILE_ANIMATION_MODE_DEFAULT, vformat("TileSetAtlasSource has no tile at %s.", Vector2i(p_atlas_coords)));
	return tiles[p_atlas_coords].animation_mode;
}
void TileSetAtlasSource::set_tile_animation_frames_count(const Vector2i p_atlas_coords, int p_frames_count) {
	ERR_FAIL_COND_MSG(!tiles.has(p_atlas_coords), vformat("TileSetAtlasSource has no tile at %s.", Vector2i(p_atlas_coords)));
	ERR_FAIL_COND(p_frames_count < 1);
	int old_size = tiles[p_atlas_coords].animation_frames_durations.size();
	if (p_frames_count == old_size) {
		return;
	}
	TileAlternativesData &tad = tiles[p_atlas_coords];
	bool room_for_tile = has_room_for_tile(p_atlas_coords, tad.size_in_atlas, tad.animation_columns, tad.animation_separation, p_frames_count, p_atlas_coords);
	ERR_FAIL_COND_MSG(!room_for_tile, "Cannot set animation columns count, tiles are already present in the space the tile would cover.");
	_clear_coords_mapping_cache(p_atlas_coords);
	tiles[p_atlas_coords].animation_frames_durations.resize(p_frames_count);
	for (int i = old_size; i < p_frames_count; i++) {
		tiles[p_atlas_coords].animation_frames_durations[i] = 1.0;
	}
	_create_coords_mapping_cache(p_atlas_coords);
	_queue_update_padded_texture();
	notify_property_list_changed();
	emit_signal(SNAME("changed"));
}
int TileSetAtlasSource::get_tile_animation_frames_count(const Vector2i p_atlas_coords) const {
	ERR_FAIL_COND_V_MSG(!tiles.has(p_atlas_coords), 1, vformat("TileSetAtlasSource has no tile at %s.", Vector2i(p_atlas_coords)));
	return tiles[p_atlas_coords].animation_frames_durations.size();
}
void TileSetAtlasSource::set_tile_animation_frame_duration(const Vector2i p_atlas_coords, int p_frame_index, real_t p_duration) {