Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a crash that occurred when calling set_contact_point_visibility() on a ContactSensor. The _data_buffer is pre-allocated with max_contact_num entries (initialized with torch.empty), but previously the method read the entire buffer rather than only the _curr_contact_num valid entries. The invalid (uninitialized) env_ids values at indices beyond _curr_contact_num would cause an out-of-bounds index into self._sim.arena_offsets, crashing the program.
Changes:
- Slice
_data_buffer["position"]with[: self._curr_contact_num]to read only valid contact positions. - Slice
_data_buffer["env_ids"]with[: self._curr_contact_num]before using the values to indexarena_offsets.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| contact_position_arena = self._data_buffer["position"][ | ||
| : self._curr_contact_num | ||
| ] | ||
| contact_offsets = self._sim.arena_offsets[ | ||
| self._data_buffer["env_ids"][: self._curr_contact_num] | ||
| ] |
There was a problem hiding this comment.
The PR checklist states "I have added tests that prove my fix is effective," but no test for set_contact_point_visibility was added in the test suite (e.g., tests/sim/sensors/test_contact.py). The existing test_fetch_contact only exercises get_data() and filter_by_user_ids(). A test calling contact_sensor.set_contact_point_visibility(visible=True) after update() should be added to verify the crash is fixed and does not regress.
Description
Fix crash when visualize contact sensor. Example:
examples/sim/sensors/create_contact_sensor.py.Type of change
Checklist
black .command to format the code base.