Expose mjtSize array fields as Int32Array in the WASM bindings - #3502
Open
VihaanAgarwal wants to merge 1 commit into
Open
Expose mjtSize array fields as Int32Array in the WASM bindings#3502VihaanAgarwal wants to merge 1 commit into
VihaanAgarwal wants to merge 1 commit into
Conversation
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.
MjModel.tex_adrismjtSize*(int64_t), and the generated binding exposes it throughtyped_memory_view, which surfaces it in JS as aBigInt64Array. Any arithmetic on its elements then throws:Cannot mix BigInt and other typesin Chrome,can't convert BigInt to numberin Firefox. That is the error behind #3496: the reporter's texture stage readstex_adr, throws, and their material setup aborts, so the geom renders with the wrong color.Scalar
mjtSizefields already avoid this by casting to int in the generator, with a comment explaining that bigint does not fit the JS number model. This extends the same policy to pointer fields: the generator now emits an accessor that returns anInt32Arraycopy instead of a 64-bit view. The wasm heap is 32-bit addressed, so the values always fit.tex_adris currently the onlymjtSize*field in the public headers, so the regeneratedbindings.hchanges just that one accessor.Before, against a two-texture model:
After:
Added an assertion to the existing texture test that fails on main and passes with this change. Full wasm suite: 175 specs, 0 failures.
Fixes #3496