Skip to content

Fix contact sensor visualization#170

Merged
matafela merged 1 commit intomainfrom
cj/fix-contact-sensor-visualize
Mar 10, 2026
Merged

Fix contact sensor visualization#170
matafela merged 1 commit intomainfrom
cj/fix-contact-sensor-visualize

Conversation

@matafela
Copy link
Collaborator

Description

Fix crash when visualize contact sensor. Example: examples/sim/sensors/create_contact_sensor.py.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have run the black . command to format the code base.
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • Dependencies have been updated, if applicable.

Copilot AI review requested due to automatic review settings March 10, 2026 09:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 index arena_offsets.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +364 to +369
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]
]
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@matafela matafela merged commit 722c844 into main Mar 10, 2026
9 checks passed
@matafela matafela deleted the cj/fix-contact-sensor-visualize branch March 10, 2026 10:35
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.

3 participants