2D meshes not rendering after despawning and respawning them
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version and features
`0.19.0-rc.3`, with default features
## \[Optional\] Relevant system information
I've reproduced this on a couple Linux machines - here's the adapter info for both of them
```rs
{ name: "NVIDIA GeForce RTX 3070 Ti Laptop GPU", vendor: 4318, device: 9440, device_type: DiscreteGpu, device_pci_bus_id: "0000:01:00.0", driver: "NVIDIA", driver_info: "595.71.05", backend: Vulkan, subgroup_min_size: 32, subgroup_max_size: 32, transient_saves_memory: false }
```
```rs
{ name: "AMD Radeon RX 7900 XTX (RADV NAVI31)", vendor: 4098, device: 29772, device_type: DiscreteGpu, device_pci_bus_id: "0000:03:00.0", driver: "radv", driver_info: "Mesa 26.1.1-arch1.2", backend: Vulkan, subgroup_min_size: 32, subgroup_max_size: 64, transient_saves_memory: false }
```
## What you did / What went wrong
I have a 2D tile-based game and was implementing undo/redo support for a map editor. I noticed that if I delete all tiles in a map, then undo - not all returned tiles would be visible. Furthermore, moving the camera around, tiles would appear and disappear when other tiles in the map went off-screen.
I managed to reproduce it with a small project that lets you spawn and despawn a grid of tiles (a pile of entities with `Mesh2d` and `MeshMaterial2d` components on them), so I don't think this would be an issue with my undo/redo system.
The project reproducing the issue: https://gitlab.com/CraftedCart/bevy_thrash2d
To reproduce using that project:
1. Compile and run the project - `cargo run`
2. Press `R` to spawn a grid of tiles
3. Use `WASD` to move the camera around. Observe how all tiles are present.
4. Press `E` to despawn all tiles
5. Press `R` again to spawn another grid of tiles
6. Observe how various tiles appear to be missing
7. Use `WASD` to move the camera around. Observe how tiles appear and disappear as tiles go on and off-screen
8. Repeat steps 4 through 7, and notice the pattern vary
## Additional information
Possibly related to #17318 - it seems similar at least if not possibly the same underlying issue, though my repro does not involve the `Sprite` component.
**A few observations I've noticed:**
- This seems depth related. If I spawn all tiles with the same Z translation, the issue doesn't seem to appear (see main.rs:87).
- Also note how most (but not all) of the pattern of missing tiles seems to be along the diagonal. This sample project spawns tiles with a depth of `x + y`, so their Z translation increases along the diagonal.
- Maybe to do with draw instancing? It looked like bevy wanted to do instanced draw calls of tiles along the diagonal.
- This also requires the mesh material to blend. Opaque or mask alpha modes cause the issue to not appear (see main.rs:48).
- Looking in RenderDoc, I am not seeing draw calls for the missing tiles.
**A video of me reproducing it with the sample project:**
I repeatedly spawn and despawn a grid of tiles, and it only appears properly the first time round
https://github.com/user-attachments/assets/d906f870-5d80-44e0-9e10-1cc0ffc001f9
Contributor guide
Assessment
This issue has not been assessed yet.