Fix incorrect data types in Python bindings of certain arrays.
The mismatch between the `py::array_t` template argument and the type of the MuJoCo struct member being wrapped caused the `py::array_t` to be constructed via an unintended constructor overload, which in turn triggered `use-after-poison` under asan. This bug affected the `geom`, `flex`, `elem`, and `vert` arrays in `mjContact`, and all array members in `mjrContext`. PiperOrigin-RevId: 608632860 Change-Id: Ic227f691041b004a0fcf0cb6fa3d62c44861d9aa
This commit is contained in:
committed by
Copybara-Service
parent
7c534a066c
commit
abf6d41b7f
@@ -529,6 +529,7 @@ class MuJoCoBindingsTest(parameterized.TestCase):
|
||||
expected_ncon = 4
|
||||
mujoco.mj_forward(self.model, self.data)
|
||||
self.assertLen(self.data.contact, expected_ncon)
|
||||
np.testing.assert_array_equal(self.data.contact.geom, [[0, 1]] * 4)
|
||||
|
||||
expected_pos = []
|
||||
for contact in self.data.contact:
|
||||
@@ -551,6 +552,13 @@ class MuJoCoBindingsTest(parameterized.TestCase):
|
||||
self.assertLen(expected_H, expected_ncon)
|
||||
np.testing.assert_array_equal(self.data.contact.H, expected_H)
|
||||
|
||||
expected_geom = []
|
||||
for i, contact in enumerate(self.data.contact):
|
||||
expected_geom.append([i, i + 1])
|
||||
contact.geom = expected_geom[-1]
|
||||
self.assertLen(expected_geom, expected_ncon)
|
||||
np.testing.assert_array_equal(self.data.contact.geom, expected_geom)
|
||||
|
||||
def test_realloc_con_efc(self):
|
||||
self.assertEmpty(self.data.contact)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user