diff --git a/bullet-featherstone/src/EntityManagementFeatures.cc b/bullet-featherstone/src/EntityManagementFeatures.cc index 775c2948b..99e40b827 100644 --- a/bullet-featherstone/src/EntityManagementFeatures.cc +++ b/bullet-featherstone/src/EntityManagementFeatures.cc @@ -206,6 +206,8 @@ Identity EntityManagementFeatures::ConstructEmptyWorld( bool EntityManagementFeatures::RemoveModel(const Identity &_modelID) { auto *model = this->ReferenceInterface(_modelID); + if (!model) + return false; return this->RemoveModelImpl(model->world, _modelID); } diff --git a/test/common_test/world_features.cc b/test/common_test/world_features.cc index 640e185cc..e1e68c0f0 100644 --- a/test/common_test/world_features.cc +++ b/test/common_test/world_features.cc @@ -434,6 +434,10 @@ TEST_F(WorldNestedModelTest, WorldConstructNestedModel) gz::physics::ForwardStep::State state; gz::physics::ForwardStep::Output output; + // Check invalid input to RemoveNestedModel method + EXPECT_FALSE(worldModel->RemoveNestedModel(1)); + EXPECT_FALSE(worldModel->RemoveNestedModel("invalid")); + // Check that we can remove models via RemoveNestedModel EXPECT_TRUE(worldModel->RemoveNestedModel(0)); EXPECT_TRUE(nestedModel->Removed());