diff --git a/crates/bevy_sprite_render/src/mesh2d/material.rs b/crates/bevy_sprite_render/src/mesh2d/material.rs index cf459b49c4776..cf7a00f6aa9ff 100644 --- a/crates/bevy_sprite_render/src/mesh2d/material.rs +++ b/crates/bevy_sprite_render/src/mesh2d/material.rs @@ -969,10 +969,6 @@ pub fn queue_material2d_meshes( specialized_material_pipeline_cache: ResMut, mut mesh_instances_queued_this_iteration_scratch_space: Local, ) { - if render_material_instances.is_empty() { - return; - } - for (view, visible_entities) in &views { let Some(view_specialized_material_pipeline_cache) = specialized_material_pipeline_cache.get(&view.retained_view_entity) @@ -1023,6 +1019,14 @@ pub fn queue_material2d_meshes( alpha_mask_phase.remove(*main_entity); } + // With no entity using this material there is nothing to queue, but the + // dequeue above still has to run: it is the only thing that takes items + // of despawned entities out of the retained phases, and it has to run on + // the very frame the last such entity goes away. + if render_material_instances.is_empty() { + continue; + } + // Now iterate over all newly-visible entities and those that need // specialization. for (render_entity, visible_entity) in dirty_specializations.iter_to_queue(