Repository: godot
Issue: TileSet: Leftover patterns after TileSet atlas source removal causes output error spam "No TileSet atlas source with id N"
Labels: topic:editor,topic:2d

### Tested versions

- Reproducible in: v4.2.1.stable.official [b09f793f5]

### System information

Godot v4.2.1.stable - Ubuntu 22.04.4 LTS 22.04 - X11 - Vulkan (Mobile) - dedicated NVIDIA GeForce GTX 860M (nvidia; 535.161.07) - Intel(R) Core(TM) i7-4710HQ CPU @ 2.50GHz (8 Threads)

### Issue description

After creating TileSet patterns using some tiles from a given atlas source (Atlas or Scene Collection):

![image](https://github.com/godotengine/godot/assets/1067772/f5833f1e-8dab-4373-918d-11ba39adbd4e)

and deleting that atlas source, all patterns using that source will be replaced with "ghost" patterns (show nothing but still selectable):

![image](https://github.com/godotengine/godot/assets/1067772/66124eba-a506-44f0-90a2-99dd8a61fdb4)

(note: the middle pattern is never visible because it uses a scene collection, which doesn't seem to support preview - it is not what this bug is about - it's easier to see the bug with Atlas tiles)

and each time user opens the TileMap panel and Output error will appear:

>   No TileSet atlas source with id 1.

(or 2, etc. depending on the ID of the removed TileSets that were used in patterns)

with one error message per pattern using a removed atlas source.

Note that if you also used said tiles/scenes in the actual tilemap, these asserts may also trigger:

> editor/plugins/tiles/tile_set_atlas_source_editor.cpp:130 - Condition "p_tile_set.is_valid() && p_tile_set->get_source(p_source_id) != p_tile_set_atlas_source" is true.
  editor/plugins/tiles/tile_atlas_view.cpp:446 - Condition "p_tile_set->get_source(p_source_id) != p_tile_set_atlas_source" is true.

![image](https://github.com/godotengine/godot/assets/1067772/804ab281-a720-4f78-b80d-eaa64ba828e9)

but they are a different issue. This issue is only about leftover **patterns** using removed tiles/scenes.

The error is even more problematic as there is no explanation of the cause of the issue in the error message. I had to inspect the TileSet tres to spot the existence of ghost patterns.

Opening the Patterns tab, user can indeed highlight empty rectangles where the patterns originally were, and delete them to fix the issue.

![Godot 4 2 1 - removing leftover patterns](https://github.com/godotengine/godot/assets/1067772/d02a2eb2-d21e-48d2-ba86-dc96953ca12d)

I suggest giving a clearer error message such as "TileSet pattern number M uses TileSet atlas source number ID N, but it is missing (must have been removed). Consider restoring the TileSet ID N, or deleting the pattern number M."

In addition, missing atlas tiles/scenes could be represented with a striped square with a warning sign, similarly to how missing tiles/scenes are shown on the TileMap after removing a TileSet atlas source.

![image](https://github.com/godotengine/godot/assets/1067772/f73aa40e-e3f2-4560-a8af-69da07ecaf0d)

Since the error is technically correct and I'm asking for more clarity, this could also be turned into a feature proposal if you prefer.

### Steps to reproduce

1. Open the sample project
2. Open demo.tscn
3. Select TileMap After Removal node and open the TileMap tab (should be automatic)
4. Check the output for errors:

>  No TileSet atlas source with id 0.
  No TileSet atlas source with id 1.

5. Now let's reproduce this. First, clear the output log to show we are really reproducing new errors.
6. Select TileMap Before Removal node > TileMap tab (this time, no errors)
7. Switch to Patterns tab > note there are 3 entries. The middle one contains a Scene from a Scene Collection and is not previewable so it looks empty, but it is valid at this point
8. Go back to Tiles tab to see Atlas sources
9. Remove one or two sources (the most obvious is to remove "icon.svg" which is an Atlas with previewable patterns, but you can also remove the Scene Collection Source) => note the red dot that shows Output errors
10. Switch back to Patterns tab to verify that patterns are now all invisible

Steps 8-9-10:

[Godot 4.2.1 - removing atlas source leaves leftover patterns.webm](https://github.com/godotengine/godot/assets/1067772/fa5d5ab5-9329-4d23-8c3a-f3b4ca046b7b)

11. Check the Output log for errors

### Minimal reproduction project (MRP)

[Godot 4.2.1 - TileSet remove first one cause ERROR: No TileSet atlas source with id 1.zip](https://github.com/godotengine/godot/files/14764216/Godot.4.2.1.-.TileSet.remove.first.one.cause.ERROR.No.TileSet.atlas.source.with.id.1.zip)