Fix SpriteList.insert() not rendering inserted sprite until next list sync#2864
Open
pvcraven wants to merge 2 commits into
Open
Fix SpriteList.insert() not rendering inserted sprite until next list sync#2864pvcraven wants to merge 2 commits into
pvcraven wants to merge 2 commits into
Conversation
added 2 commits
July 15, 2026 16:03
SpriteList.insert() updated the CPU-side index data but never set self._sprite_index_changed = True, unlike append() and every other mutating method. As a result, a sprite added via insert() was present in the list but never uploaded to the GPU index buffer, so it was not rendered until an unrelated flag-setting operation forced a sync. Set the flag at the end of insert() to mirror append(). Fixes #2863
append() raises ValueError when a textureless sprite is added to an initialized SpriteList. insert() silently accepted it. Mirror the same guard in insert() for consistency between the two entry points. Note: this is a validation-only change; the atlas registration itself is already handled by _update_all() for both append() and insert().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2863.
Primary fix: inserted sprites not rendered
SpriteList.insert()updated the CPU-side index data (_sprite_index_data) but never setself._sprite_index_changed = True. Every other mutating method (append,remove,pop,swap,reverse,sort,clear) sets it.Because
_write_sprite_buffers_to_gpu()only uploads the index buffer when that flag is set, a sprite added viainsert()was fully present in the list (updated, collides, removable) but never rendered — it silently appeared only when some later unrelated operation set the flag and forced a full sync. This produced hard-to-diagnose intermittent "invisible sprite" bugs.Fix: set
self._sprite_index_changed = Trueat the end ofinsert(), mirroringappend().Secondary: texture validation consistency
append()raisesValueErrorwhen a textureless sprite is added to an initialized list, butinsert()did not. Added the same guard toinsert()so the two entry points behave identically.Note: this is validation-only. The atlas registration itself is already handled by
_update_all()for bothappend()andinsert(), so there was no atlas/rendering bug there.Verification
draw().test_it_can_insert_in_a_spritelistconfirming the index-changed flag is set.test_insert_requires_texture_when_initializedcovering the validation guard.pytest tests/unit/spritelist/test_spritelist.pypasses (19 passed);ruffclean.