Skip to content

Fix 2D flicker by always dequeueing retained phase items (#25163) - #25253

Open
morr wants to merge 1 commit into
bevyengine:mainfrom
morr:fix-25163-on-main
Open

Fix 2D flicker by always dequeueing retained phase items (#25163)#25253
morr wants to merge 1 commit into
bevyengine:mainfrom
morr:fix-25163-on-main

Conversation

@morr

@morr morr commented Aug 1, 2026

Copy link
Copy Markdown

Objective

Fixes #25163.

queue_material2d_meshes is the only system that takes items out of the
retained 2D phases, and it returns early when render_material_instances
is empty. That is the frame the last entity using that material type gets
despawned, so its items never get removed and stay in the phase for good.

They also keep the batch_range they had when they were last batched,
since batch_and_prepare_sorted_render_phase only rewrites the range of
items that still have a RenderMesh2dInstance. render_range advances the
index by batch_range.len() after every draw, so an item left over from a
batch of three hides the two live items behind it. With equal sort keys the
order changes from frame to frame, which is why it shows up as flicker
instead of something permanently missing.

The early return is older than the dequeue loop (#17567 added it back when
the system only queued, #23083 added the removal). The 3D
queue_material_meshes doesn't have one.

Solution

Move the check below the dequeue loop and make it a continue. There is
still nothing to queue when no entity uses the material, but removal now
always happens.

Testing

In my own app after applying the patch tree shadows stopped flickering
image

…25163)

Fixes bevyengine#25163.

`queue_material2d_meshes` is the only system that takes items out of the
retained 2D phases, and it returns early when `render_material_instances`
is empty. That is the frame the last entity using that material type gets
despawned, so its items never get removed and stay in the phase for good.

Move the check below the dequeue loop and make it a `continue`. There is
still nothing to queue when no entity uses the material, but removal now
always happens.
@morr morr mentioned this pull request Aug 1, 2026
@kfc35 kfc35 added this to the 0.19.1 milestone Aug 1, 2026
@kfc35 kfc35 added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 1, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

Sprite flickering

2 participants