diff --git a/python/mujoco/codegen/generate_spec_bindings.py b/python/mujoco/codegen/generate_spec_bindings.py index 700ff883..2db53870 100644 --- a/python/mujoco/codegen/generate_spec_bindings.py +++ b/python/mujoco/codegen/generate_spec_bindings.py @@ -170,11 +170,12 @@ def _ptr_binding_code( return MjTypeVec(self.{fullvarname}->data(), self.{fullvarname}->size()); }}, - []({rawclassname}& self, py::object rhs) {{ + []({rawclassname}& self, py::bytes& rhs) {{ self.{fullvarname}->clear(); self.{fullvarname}->reserve(py::len(rhs)); - for (auto val : rhs) {{ - self.{fullvarname}->push_back(py::cast(val)); + std::string_view rhs_view = py::cast(rhs); + for (auto val : rhs_view) {{ + self.{fullvarname}->push_back(static_cast(val)); }} }}, py::return_value_policy::move);""" elif vartype == 'mjStringVec': diff --git a/python/mujoco/specs_test.py b/python/mujoco/specs_test.py index bd9997e1..e0d3e836 100644 --- a/python/mujoco/specs_test.py +++ b/python/mujoco/specs_test.py @@ -891,6 +891,12 @@ class SpecsTest(absltest.TestCase): with self.assertRaises(IndexError): material.textures[-1] = 'x' + def test_assign_texture(self): + spec = mujoco.MjSpec() + texture = spec.add_texture(name='texture', height=2, width=2) + texture.data = np.zeros((2, 2, 3), dtype=np.uint8).tobytes() + spec.compile() + def test_attach_units(self): child = mujoco.MjSpec() parent = mujoco.MjSpec()