Skip to content

Fix: Avoid array destructuring in observer serializer due to Bun/JSC bug#211

Open
americanjeff wants to merge 6 commits into
NateTheGreatt:mainfrom
americanjeff:push-nxwltoprprxn
Open

Fix: Avoid array destructuring in observer serializer due to Bun/JSC bug#211
americanjeff wants to merge 6 commits into
NateTheGreatt:mainfrom
americanjeff:push-nxwltoprprxn

Conversation

@americanjeff
Copy link
Copy Markdown

Problem

The observer serializer uses array destructuring which can trigger a bug in Bun's JavaScriptCore engine under certain conditions.

In ObserverSerializer.ts, the code:

const [entityId, type, componentId, targetId, relationData] = queue[i]

Can fail with TypeError: undefined is not a function due to a Bun/JSC bug related to Symbol.iterator and typed arrays.

Bug References

Solution

Use explicit array indexing instead of destructuring:

const entry = queue[i]
const entityId = entry[0]
const type = entry[1]
const componentId = entry[2]
const targetId = entry[3]
const relationData = entry[4]

Testing

This fix has been tested in a game project that was experiencing crashes after many turns. After applying this fix, the crashes no longer occur.

American Jeff added 6 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant