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

}
					p.pop_front();
				}
			}
		} else if (what == "shapes") {
			Array p = p_value;
			for (int i = 0; i < p.size(); i++) {
				CompatibilityShapeData csd;
				Dictionary d = p[i];
				for (int j = 0; j < d.size(); j++) {
					String key = d.get_key_at_index(j);
					if (key == "autotile_coord") {
						csd.autotile_coords = d[key];
					} else if (key == "one_way") {
						csd.one_way = d[key];
					} else if (key == "one_way_margin") {
						csd.one_way_margin = d[key];
					} else if (key == "shape") {
						csd.shape = d[key];
					} else if (key == "shape_transform") {
						csd.transform = d[key];
					}
				}
				ctd->shapes.push_back(csd);
			}
		} else if (what == "occluder") {
			ctd->occluder = p_value;
		} else if (what == "navigation") {
			ctd->navigation = p_value;
			/*