Skip to content

Commit 694d954

Browse files
authored
Fix ambiguous queue_material_tilemap_meshes ordering
It was possible for `queue_material_tilemap_meshes` to run prior to `prepare` which would result in nothing rendering. This would only occur in scenarios where other code inserted a system dependent on `mut commands: Commands` into the `Queue` set. The `bevy-egui` library was doing so and was thus introducing behavior where `bevy-ecs-tilemap` would intermittently not render anything due to improper system ordering.
1 parent 25def41 commit 694d954

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/render/material.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use super::{
3030
chunk::{ChunkId, RenderChunk2dStorage},
3131
draw::DrawTilemapMaterial,
3232
pipeline::{TilemapPipeline, TilemapPipelineKey},
33+
prepare,
3334
queue::{ImageBindGroups, TilemapViewBindGroup},
3435
};
3536

@@ -127,7 +128,13 @@ where
127128
.add_systems(
128129
Render,
129130
(
130-
queue_material_tilemap_meshes::<M>.in_set(RenderSet::Queue),
131+
// Ensure `queue_material_tilemap_meshes` runs after `prepare::prepare` because `prepare` calls `commands.spawn` with `ChunkId`
132+
// and that data is then consumed by `queue_material_tilemap_mesh`. This is important because `prepare` is part of the `PrepareAssets`
133+
// set. Bevy is loose on its expectation of when systems in the `PrepareAssets` set execute (for performance) and only needs them
134+
// to run before the `Prepare` set (which is after Queue). This invites the possibility of an intermittent incorrect ordering dependent
135+
// on the scheduler.
136+
queue_material_tilemap_meshes::<M>.in_set(RenderSet::Queue)
137+
.after(prepare::prepare),
131138
bind_material_tilemap_meshes::<M>.in_set(RenderSet::PrepareBindGroups),
132139
),
133140
);

0 commit comments

Comments
 (0)