### 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)

int c = p_data.size();
	const int *r = p_data.ptr();
	int offset = 3;
	ERR_FAIL_COND_MSG(c % offset != 0, "Corrupted tile data.");
	clear();
	for (int i = 0; i < c; i += offset) {
		const uint8_t *ptr = (const uint8_t *)&r[i];
		uint8_t local[12];
		for (int j = 0; j < 12; j++) {
			local[j] = ptr[j];
		}
#ifdef BIG_ENDIAN_ENABLED
		SWAP(local[0], local[3]);
		SWAP(local[1], local[2]);
		SWAP(local[4], local[7]);
		SWAP(local[5], local[6]);
		SWAP(local[8], local[11]);
		SWAP(local[9], local[10]);
#endif
		int16_t x = decode_uint16(&local[0]);
		int16_t y = decode_uint16(&local[2]);
		uint16_t source_id = decode_uint16(&local[4]);
		uint16_t atlas_coords_x = decode_uint16(&local[6]);
		uint16_t atlas_coords_y = decode_uint16(&local[8]);
		uint16_t alternative_tile = decode_uint16(&local[10]);
		set_cell(Vector2i(x, y), source_id, Vector2i(atlas_coords_x, atlas_coords_y), alternative_tile);
	}
	emit_signal(SNAME("changed"));
}
Vector<int> TileMapPattern::_get_tile_data() const {