Fix #3368: clip hfield grid indices before int cast in MJX collision#3373
Open
Ashutosh0x wants to merge 1 commit into
Open
Fix #3368: clip hfield grid indices before int cast in MJX collision#3373Ashutosh0x wants to merge 1 commit into
Ashutosh0x 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.
Problem
In
_hfield_collision, the computed grid indicescminandrminare float values that may be very large (e.g.+infor beyond int32 range) when the colliding object is far outside the height field. Calling.astype(int)directly on such values produces an integer overflow, which generates a JAX/XLA warning and results in undefined behaviour on GPU targets.Note: PR #3369 fixes a related overflow in the
_box_boxand_convex_convexpaths. This PR addresses the remaining overflow in the hfield path.Fixes #3368.
Changes
mjx/mujoco/mjx/_src/collision_convex.pyClip
cminandrminto a valid range before calling.astype(int):The clip bounds match the existing clamps inside
make_prisms(jp.clip(ri, 0, h.nrow - 2)/jp.clip(ci, 0, h.ncol - 2)), so the observable collision result is unchanged for in-bounds objects. For out-of-bounds objects the prisms simply land on the nearest valid row/column, which is the correct fallback behaviour.