Fix: SoA diff serializer correctly handles undefined values for entities without components#208
Open
americanjeff wants to merge 5 commits into
Open
Fix: SoA diff serializer correctly handles undefined values for entities without components#208americanjeff wants to merge 5 commits into
americanjeff wants to merge 5 commits into
Conversation
added 5 commits
March 8, 2026 11:34
…ntities - Add check for undefined shadow values in hasChanged function - Float values (f32/f64) now serialize correctly for new entities in diff mode - Add tests demonstrating the bug and verifying the fix
Goal of this change is to prevent recycled EID corruption in SoA diff serialization - Add getRemovals() to ObserverSerializerFunction: tracks entity IDs removed since last call via onRemove(networkedTag) observer - Add getRemovals option to SoASerializerOptions: before each diff pass, clears ALL shadow entries for removed EIDs (entity-level, not per-component) because the serializer processes all component arrays for every entity — stale typed-array values left by bitECS can contaminate shadows for any component at a recycled slot - Add clearEntity() method to SoASerializerFunction for manual shadow clearing - Add EntityRecycling.test.ts with three tests covering the recycling scenario
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
hasChangedfunction in SoASerializer to properly handleundefinedarray slots when entities don't have all componentsRoot Cause
When using diff-mode serialization over all entities (e.g.,
getAllEntities()), entities that don't have a particular component haveundefinedslots in that component's arrays. ThegetShadowfunction was initializing shadow arrays with0, andhasChangedwas treatingundefinedvsundefinedas a change (returningtrueinstead offalse).Changes
getShadow: Remove.fill(0)- shadow arrays now initialize withundefinedslotshasChanged: Add proper handling for undefined values:undefined→ no change, returnfalseundefined, current defined → first time seeing value, returntrueundefined, shadow defined → entity lost component, returntrueTest Plan
All existing tests pass (162 tests).