From 1c098af287c5e80271314893ece198516cd0aa8f Mon Sep 17 00:00:00 2001 From: ahcorde Date: Mon, 29 Jun 2020 16:19:26 +0200 Subject: [PATCH 1/6] Fixed crash when collision size is zero Signed-off-by: ahcorde --- gazebo/rendering/Visual.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gazebo/rendering/Visual.cc b/gazebo/rendering/Visual.cc index a200e71128..c3e2507dcf 100644 --- a/gazebo/rendering/Visual.cc +++ b/gazebo/rendering/Visual.cc @@ -793,9 +793,14 @@ void Visual::SetScale(const math::Vector3 &_scale) this->dataPtr->scale = _scale.Ign(); - this->dataPtr->sceneNode->setScale( - Conversions::Convert(math::Vector3(this->dataPtr->scale))); - + if (!isnan(this->dataPtr->scale.X()) && !isnan(this->dataPtr->scale.Y()) + && !isnan(this->dataPtr->scale.Z())) + { + this->dataPtr->sceneNode->setScale( + Conversions::Convert(this->dataPtr->scale)); + } else { + gzerr << Name() << " Scale contains NaNs. Collisions may not visualize properly." << std::endl; + } // Scale selection object in case we have one attached. Other children were // scaled from UpdateGeomSize for (auto child : this->dataPtr->children) From a1ce807fc5533279d0962faffcffd9514fbd67b9 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Fri, 3 Jul 2020 09:25:26 +0200 Subject: [PATCH 2/6] Using ignition::math::isnan Signed-off-by: ahcorde --- gazebo/rendering/Visual.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gazebo/rendering/Visual.cc b/gazebo/rendering/Visual.cc index c3e2507dcf..00f2baad19 100644 --- a/gazebo/rendering/Visual.cc +++ b/gazebo/rendering/Visual.cc @@ -793,8 +793,9 @@ void Visual::SetScale(const math::Vector3 &_scale) this->dataPtr->scale = _scale.Ign(); - if (!isnan(this->dataPtr->scale.X()) && !isnan(this->dataPtr->scale.Y()) - && !isnan(this->dataPtr->scale.Z())) + if (!ignition::math::isnan(this->dataPtr->scale.X()) + && !ignition::math::isnan(this->dataPtr->scale.Y()) + && !ignition::math::isnan(this->dataPtr->scale.Z())) { this->dataPtr->sceneNode->setScale( Conversions::Convert(this->dataPtr->scale)); From 2c72414de1971af9185b7ab76e42fc5559341efa Mon Sep 17 00:00:00 2001 From: ahcorde Date: Fri, 3 Jul 2020 16:39:15 +0200 Subject: [PATCH 3/6] Improved error message Signed-off-by: ahcorde --- gazebo/rendering/Visual.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gazebo/rendering/Visual.cc b/gazebo/rendering/Visual.cc index 00f2baad19..cc791c53f5 100644 --- a/gazebo/rendering/Visual.cc +++ b/gazebo/rendering/Visual.cc @@ -800,7 +800,8 @@ void Visual::SetScale(const math::Vector3 &_scale) this->dataPtr->sceneNode->setScale( Conversions::Convert(this->dataPtr->scale)); } else { - gzerr << Name() << " Scale contains NaNs. Collisions may not visualize properly." << std::endl; + gzerr << Name() << ": Size of the collision contains one or several zeros." << + " Collisions may not visualize properly." << std::endl; } // Scale selection object in case we have one attached. Other children were // scaled from UpdateGeomSize From 5bbea782fdef504975cb8cde9ebf6549339c7317 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Thu, 9 Jul 2020 11:35:36 +0200 Subject: [PATCH 4/6] fixed method to get the name of the visual Signed-off-by: ahcorde --- gazebo/rendering/Visual.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gazebo/rendering/Visual.cc b/gazebo/rendering/Visual.cc index cc791c53f5..092a029265 100644 --- a/gazebo/rendering/Visual.cc +++ b/gazebo/rendering/Visual.cc @@ -800,7 +800,7 @@ void Visual::SetScale(const math::Vector3 &_scale) this->dataPtr->sceneNode->setScale( Conversions::Convert(this->dataPtr->scale)); } else { - gzerr << Name() << ": Size of the collision contains one or several zeros." << + gzerr << GetName() << ": Size of the collision contains one or several zeros." << " Collisions may not visualize properly." << std::endl; } // Scale selection object in case we have one attached. Other children were From c27d029c0c5e9d49756f14e73f708a8f51190c8b Mon Sep 17 00:00:00 2001 From: ahcorde Date: Mon, 13 Jul 2020 10:40:36 +0200 Subject: [PATCH 5/6] Fixed else brackets Signed-off-by: ahcorde --- gazebo/rendering/Visual.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gazebo/rendering/Visual.cc b/gazebo/rendering/Visual.cc index 092a029265..7ba675cf6f 100644 --- a/gazebo/rendering/Visual.cc +++ b/gazebo/rendering/Visual.cc @@ -799,7 +799,9 @@ void Visual::SetScale(const math::Vector3 &_scale) { this->dataPtr->sceneNode->setScale( Conversions::Convert(this->dataPtr->scale)); - } else { + } + else + { gzerr << GetName() << ": Size of the collision contains one or several zeros." << " Collisions may not visualize properly." << std::endl; } From 6db24e1f9a2eb2e3ea089acbac76c95d30796dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez=20Cordero?= Date: Thu, 23 Jul 2020 10:01:47 +0200 Subject: [PATCH 6/6] [Gazebo 9] Added test to check collisions equal to zero (#2788) * Added test to check collisions equal to zero Signed-off-by: ahcorde * Included feedback Signed-off-by: ahcorde * make linters happy Signed-off-by: ahcorde * Update Visual_TEST.cc --- gazebo/rendering/Visual_TEST.cc | 36 +++++++++++++++ worlds/collision_zero.world | 79 +++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 worlds/collision_zero.world diff --git a/gazebo/rendering/Visual_TEST.cc b/gazebo/rendering/Visual_TEST.cc index 9803ed9913..6e03e8c43d 100644 --- a/gazebo/rendering/Visual_TEST.cc +++ b/gazebo/rendering/Visual_TEST.cc @@ -1514,6 +1514,42 @@ TEST_F(Visual_TEST, ConvertVisualType) rendering::Visual::ConvertVisualType(msgs::Visual::PHYSICS)); } +TEST_F(Visual_TEST, CollisionZero) +{ + // This test checks that there isn't a segmentation fault when inserting + // zero collision geometries. + // Load a world containing 3 simple shapes with collision geometry equals + // to zero. + Load("worlds/collision_zero.world"); + + // Get the scene + gazebo::rendering::ScenePtr scene = gazebo::rendering::get_scene(); + ASSERT_NE(scene, nullptr); + + // Wait until all models are inserted + int sleep = 0; + int maxSleep = 10; + rendering::VisualPtr box, sphere, cylinder; + while ((!box || !sphere || !cylinder) && sleep < maxSleep) + { + event::Events::preRender(); + event::Events::render(); + event::Events::postRender(); + + box = scene->GetVisual("box"); + cylinder = scene->GetVisual("cylinder"); + sphere = scene->GetVisual("sphere"); + common::Time::MSleep(1000); + sleep++; + } + scene->ShowCollisions(true); + // box + ASSERT_NE(box, nullptr); + // cylinder + ASSERT_NE(cylinder, nullptr); + // sphere + ASSERT_NE(sphere, nullptr); +} ///////////////////////////////////////////////// TEST_F(Visual_TEST, Scale) { diff --git a/worlds/collision_zero.world b/worlds/collision_zero.world new file mode 100644 index 0000000000..76e420119b --- /dev/null +++ b/worlds/collision_zero.world @@ -0,0 +1,79 @@ + + + + + model://ground_plane + + + model://sun + + + 0 0 0.5 0 0 0 + + + + + 0 0 0 + + + + + + + 1 1 1 + + + + + + + + + + 0 1.5 0.5 0 0 0 + + + + + 0 + + + + + + + 0.5 + + + + + + + + + + 0 -1.5 0.5 0 1.5707 0 + + + + + 0 + 0 + + + + + + + 0.5 + 1.0 + + + + + + + + + +