diff --git a/src/user/user_model.cc b/src/user/user_model.cc index ee4f83f0..4470a082 100644 --- a/src/user/user_model.cc +++ b/src/user/user_model.cc @@ -4515,10 +4515,9 @@ void mjCModel::TryCompile(mjModel*& m, mjData*& d, const mjVFS* vfs) { } // check mass and inertia of moving bodies - if (bodies_.size() > 1) { - // we ignore the first body as it is the world body - if (!CheckBodiesMassInertia(std::vector(bodies_.begin()+1, bodies_.end()))) { - throw mjCError(0, "mass and inertia of moving bodies must be larger than mjMINVAL"); + for (int i=1; i < bodies_.size(); i++) { + if (!bodies_[i]->joints.empty() && !CheckBodyMassInertia(bodies_[i])) { + throw mjCError(bodies_[i], "mass and inertia of moving bodies must be larger than mjMINVAL"); } } @@ -4763,20 +4762,6 @@ uint64_t mjCModel::Signature() { -bool mjCModel::CheckBodiesMassInertia(std::vector bodies) { - // check mass and inertia of moving bodies - for (int i=0; i < bodies.size(); i++) { - if (!bodies[i]->joints.empty()) { - if (!CheckBodyMassInertia(bodies[i])) { - return false; - } - } - } - return true; -} - - - bool mjCModel::CheckBodyMassInertia(mjCBody* body) { // check if body has valid mass and inertia if (body->mass >= mjMINVAL && diff --git a/src/user/user_model.h b/src/user/user_model.h index 75b79124..a7dcbe8b 100644 --- a/src/user/user_model.h +++ b/src/user/user_model.h @@ -425,9 +425,6 @@ class mjCModel : public mjCModel_, private mjSpec { // compute qpos0 void ComputeReference(); - // return true if all bodies have valid mass and inertia - bool CheckBodiesMassInertia(std::vector bodies); - // return true if body has valid mass and inertia bool CheckBodyMassInertia(mjCBody* body); diff --git a/test/user/user_mesh_test.cc b/test/user/user_mesh_test.cc index 759561b2..d93a4822 100644 --- a/test/user/user_mesh_test.cc +++ b/test/user/user_mesh_test.cc @@ -529,7 +529,7 @@ TEST_F(MjCMeshTest, TinyInertiaFails) { - + @@ -542,6 +542,7 @@ TEST_F(MjCMeshTest, TinyInertiaFails) { error.data(), HasSubstr( "mass and inertia of moving bodies must be larger than mjMINVAL")); + EXPECT_THAT(error.data(), HasSubstr("Element name 'tiny_body'")); } TEST_F(MjCMeshTest, FlippedFaceAllowedLegacyInertia) { diff --git a/test/user/user_model_test.cc b/test/user/user_model_test.cc index 3293b257..80697969 100644 --- a/test/user/user_model_test.cc +++ b/test/user/user_model_test.cc @@ -196,7 +196,7 @@ TEST_F(UserCModelTest, NestedZeroMassBodiesFail) { - + @@ -214,6 +214,7 @@ TEST_F(UserCModelTest, NestedZeroMassBodiesFail) { error, HasSubstr( "mass and inertia of moving bodies must be larger than mjMINVAL")); + EXPECT_THAT(error, HasSubstr("Element name 'bad'")); mj_deleteModel(model); }