Fix BigInt/mjtSize WASM bindings and material transparency in demo viewer (#3496) - #3501
Open
Adityakk9031 wants to merge 2 commits into
Open
Fix BigInt/mjtSize WASM bindings and material transparency in demo viewer (#3496)#3501Adityakk9031 wants to merge 2 commits into
Adityakk9031 wants to merge 2 commits into
Conversation
Contributor
Author
|
@yuvaltassa have a look |
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.
Fixes #3496
Root Cause
MjModel.tex_adrismjtSize*(int64_t*). Emscripten'styped_memory_viewover a 64-bit integer pointer surfaces as aBigInt64Arrayin JavaScript. Any arithmetic on its elements (e.g.tex_adr[i] * 3to compute byte offsets) throws:Cannot mix BigInt and other types, use explicit conversionscan't convert BigInt to numberThis is the root cause of the viewer error
[mujoco stage: geom[0] texture] can't convert BigInt to number: the texture staging code readstex_adr, hitsBigInt, and the material setup aborts — leaving the geom with the wrong color.Scalar
mjtSizefields already avoid this by casting tointin the code generator. This PR extends the same policy to pointer (array) fields.Changes
1.
wasm/codegen/generators/structs.py— Binding generator (root cause fix)When generating an accessor for a dynamically-sized pointer field whose inner type is
mjtSize, emit anInt32Arraycopy instead of aBigInt64Arraytyped_memory_view. The WASM heap is 32-bit addressed so values always fit anint.2.
wasm/codegen/generated/bindings.h— Regenerated outputtex_adr()now returns anInt32Arraycopy, consistent withtex_height,tex_width, andtex_nchannel.3.
wasm/tests/bindings_test.ts— Test coverageAdded assertions that:
tex_adris anInt32Array(notBigInt64Array)tex_adr[0]does not throw4.
wasm/demo_app/app.ts— Defensive consumer-side fixesNumber()coercion on allmjvGeomfields (type,dataid,size,rgba,mat,pos) andgeoms.size()/mjData.timegeoms.get(i)call (memory leak)transparentcondition:rgba[3] < 1.0instead ofrgba[3] !== 0Before / After