From 75f196c7efd8a2637437b35492e9ee5484ba5cda Mon Sep 17 00:00:00 2001 From: Alessio Quaglino Date: Mon, 28 Apr 2025 16:22:55 -0700 Subject: [PATCH] Add missing PointToLocal call in mjCPlugin copy constructor. PiperOrigin-RevId: 752486555 Change-Id: I08b14476b9098e6473a4c00918ef3f9a287f35f6 --- python/mujoco/specs_test.py | 11 +++++++++++ src/user/user_objects.cc | 11 +++++++++++ src/user/user_objects.h | 3 +++ 3 files changed, 25 insertions(+) diff --git a/python/mujoco/specs_test.py b/python/mujoco/specs_test.py index 210d833f..e8aafa23 100644 --- a/python/mujoco/specs_test.py +++ b/python/mujoco/specs_test.py @@ -861,6 +861,17 @@ class SpecsTest(absltest.TestCase): self.assertEqual(model.nplugin, 1) self.assertEqual(model.npluginattr, 7) self.assertEqual(model.body_plugin[1], 0) + attributes = (''.join([chr(i) for i in model.plugin_attr]).split(chr(0))) + self.assertEqual(attributes[:2], ['10', '1']) + + copy = spec.copy() # before assigning the new config + wrong_config = {'wrong': '10', 'bend': '1'} + for s in [spec, copy]: + s.plugins[0].config = wrong_config + with self.assertRaisesRegex( + ValueError, "Error: unrecognized attribute 'plugin:wrong'" + ): + s.compile() def test_recompile_error(self): main_xml = """ diff --git a/src/user/user_objects.cc b/src/user/user_objects.cc index d609621c..cff97b72 100644 --- a/src/user/user_objects.cc +++ b/src/user/user_objects.cc @@ -7271,6 +7271,8 @@ mjCPlugin::mjCPlugin(mjCModel* _model) { spec.plugin_name = &plugin_name; spec.name = &name; spec.info = &info; + + PointToLocal(); } @@ -7289,11 +7291,20 @@ mjCPlugin& mjCPlugin::operator=(const mjCPlugin& other) { parent = this; plugin_slot = other.plugin_slot; } + PointToLocal(); return *this; } +void mjCPlugin::PointToLocal() { + spec.element = static_cast(this); + spec.name = &name; + spec.info = &info; +} + + + // compiler void mjCPlugin::Compile(void) { mjCPlugin* plugin_instance = this; diff --git a/src/user/user_objects.h b/src/user/user_objects.h index 16aa57af..bfec0797 100644 --- a/src/user/user_objects.h +++ b/src/user/user_objects.h @@ -1587,6 +1587,9 @@ class mjCPlugin : public mjCPlugin_ { mjCPlugin(mjCModel*); mjCPlugin(const mjCPlugin& other); mjCPlugin& operator=(const mjCPlugin& other); + + void PointToLocal(); + mjsPlugin spec; mjCBase* parent; // parent object (only used when generating error message) int plugin_slot; // global registered slot number of the plugin