File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -1135,5 +1135,29 @@ def test_bind(self):
11351135 ):
11361136 print (mj_model .bind (joints ).invalid )
11371137
1138+ def test_incorrect_hfield_size (self ):
1139+ nrow = 300
1140+ ncol = 400
1141+ hdata = np .random .uniform (size = (1 , 1 ))
1142+ model_spec = mujoco .MjSpec ()
1143+ model_spec .add_hfield (
1144+ name = 'hfield' ,
1145+ size = [1 , 1 , 1 , 1e-3 ],
1146+ ncol = ncol ,
1147+ nrow = nrow ,
1148+ userdata = hdata .flatten (),
1149+ )
1150+ model_spec .worldbody .add_geom (
1151+ name = 'hfield' ,
1152+ type = mujoco .mjtGeom .mjGEOM_HFIELD ,
1153+ pos = np .array ([0 , 0 , 1 ]),
1154+ hfieldname = 'hfield' ,
1155+ )
1156+ with self .assertRaisesRegex (
1157+ ValueError , r"Error: elevation data length must match nrow\*ncol\n"
1158+ "Element name 'hfield', id 0" ,
1159+ ):
1160+ model_spec .compile ()
1161+
11381162if __name__ == '__main__' :
11391163 absltest .main ()
Original file line number Diff line number Diff line change @@ -3696,6 +3696,9 @@ void mjCHField::Compile(const mjVFS* vfs) {
36963696
36973697 // copy userdata into data
36983698 if (!userdata_.empty ()) {
3699+ if (nrow*ncol != userdata_.size ()) {
3700+ throw mjCError (this , " elevation data length must match nrow*ncol" );
3701+ }
36993702 data.assign (nrow*ncol, 0 );
37003703 if (data.empty ()) {
37013704 throw mjCError (this , " could not allocate buffers in hfield" );
You can’t perform that action at this time.
0 commit comments