Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More nullptr checking on visuals and base axis #486

Merged
merged 5 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/ignition/rendering/base/BaseAxisVisual.hh
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ namespace ignition
{
auto arrow = std::dynamic_pointer_cast<rendering::ArrowVisual>(
this->ChildByIndex(i));
arrow->SetVisible(_visible);
if (arrow != nullptr)
arrow->SetVisible(_visible);
}
}
}
Expand Down
31 changes: 28 additions & 3 deletions ogre/src/OgreVisual.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ void OgreVisual::SetWireframe(bool _show)
if (this->dataPtr->wireframe == _show)
return;

if (!this->ogreNode)
return;

this->dataPtr->wireframe = _show;
for (unsigned int i = 0; i < this->ogreNode->numAttachedObjects();
i++)
Expand Down Expand Up @@ -100,6 +103,9 @@ bool OgreVisual::Wireframe() const
//////////////////////////////////////////////////
void OgreVisual::SetVisible(bool _visible)
{
if (!this->ogreNode)
return;

this->ogreNode->setVisible(_visible);
}

Expand All @@ -124,6 +130,19 @@ GeometryStorePtr OgreVisual::Geometries() const
//////////////////////////////////////////////////
bool OgreVisual::AttachGeometry(GeometryPtr _geometry)
{
if (!_geometry)
{
ignerr << "Cannot attach null geometry." << std::endl;

return false;
}

if (!this->ogreNode)
{
ignerr << "Cannot attach geometry, null Ogre node." << std::endl;
return false;
}

OgreGeometryPtr derived =
std::dynamic_pointer_cast<OgreGeometry>(_geometry);

Expand Down Expand Up @@ -154,7 +173,10 @@ bool OgreVisual::AttachGeometry(GeometryPtr _geometry)
bool OgreVisual::DetachGeometry(GeometryPtr _geometry)
{
if (!this->ogreNode)
return true;
{
ignerr << "Cannot detach geometry, null Ogre node." << std::endl;
return false;
}

OgreGeometryPtr derived =
std::dynamic_pointer_cast<OgreGeometry>(_geometry);
Expand Down Expand Up @@ -200,6 +222,9 @@ void OgreVisual::BoundsHelper(ignition::math::AxisAlignedBox &_box,
void OgreVisual::BoundsHelper(ignition::math::AxisAlignedBox &_box,
bool _local, const ignition::math::Pose3d &_pose) const
{
if (!this->ogreNode)
return;

this->ogreNode->_updateBounds();
this->ogreNode->_update(false, true);

Expand Down Expand Up @@ -228,6 +253,7 @@ void OgreVisual::BoundsHelper(ignition::math::AxisAlignedBox &_box,
Ogre::Vector3 ogreMin = bb.getMinimum();
Ogre::Vector3 ogreMax = bb.getMaximum();

// Get ogre bounding boxes and size to object's scale
min = scale * ignition::math::Vector3d(ogreMin.x, ogreMin.y, ogreMin.z);
max = scale * ignition::math::Vector3d(ogreMax.x, ogreMax.y, ogreMax.z);
box.Min() = min,
Expand All @@ -240,9 +266,8 @@ void OgreVisual::BoundsHelper(ignition::math::AxisAlignedBox &_box,
if (_local)
{
ignition::math::Pose3d worldPose = this->WorldPose();
ignition::math::Quaternion parentRot = _pose.Rot();
ignition::math::Vector3d parentPos = _pose.Pos();
ignition::math::Quaternion parentRotInv = parentRot.Inverse();
ignition::math::Quaternion parentRotInv = _pose.Rot().Inverse();
ignition::math::Pose3d localTransform =
ignition::math::Pose3d(
(parentRotInv * (worldPose.Pos() - parentPos)),
Expand Down
24 changes: 23 additions & 1 deletion ogre2/src/Ogre2Visual.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ void Ogre2Visual::SetWireframe(bool _show)
if (this->dataPtr->wireframe == _show)
return;

if (!this->ogreNode)
return;

this->dataPtr->wireframe = _show;
for (unsigned int i = 0; i < this->ogreNode->numAttachedObjects();
i++)
Expand Down Expand Up @@ -96,6 +99,9 @@ bool Ogre2Visual::Wireframe() const
//////////////////////////////////////////////////
void Ogre2Visual::SetVisible(bool _visible)
{
if (!this->ogreNode)
return;

this->ogreNode->setVisible(_visible);
}

Expand Down Expand Up @@ -130,6 +136,12 @@ bool Ogre2Visual::AttachGeometry(GeometryPtr _geometry)
return false;
}

if (!this->ogreNode)
{
ignerr << "Cannot attach geometry, null Ogre node." << std::endl;
return false;
}

Ogre2GeometryPtr derived =
std::dynamic_pointer_cast<Ogre2Geometry>(_geometry);

Expand Down Expand Up @@ -164,6 +176,12 @@ bool Ogre2Visual::AttachGeometry(GeometryPtr _geometry)
//////////////////////////////////////////////////
bool Ogre2Visual::DetachGeometry(GeometryPtr _geometry)
{
if (!this->ogreNode)
{
ignerr << "Cannot detach geometry, null Ogre node." << std::endl;
return false;
}

Ogre2GeometryPtr derived =
std::dynamic_pointer_cast<Ogre2Geometry>(_geometry);

Expand All @@ -175,7 +193,8 @@ bool Ogre2Visual::DetachGeometry(GeometryPtr _geometry)
return false;
}

this->ogreNode->detachObject(derived->OgreObject());
if (nullptr != derived->OgreObject())
this->ogreNode->detachObject(derived->OgreObject());
derived->SetParent(nullptr);
return true;
}
Expand Down Expand Up @@ -207,6 +226,9 @@ void Ogre2Visual::BoundsHelper(ignition::math::AxisAlignedBox &_box,
void Ogre2Visual::BoundsHelper(ignition::math::AxisAlignedBox &_box,
bool _local, const ignition::math::Pose3d &_pose) const
{
if (!this->ogreNode)
return;

ignition::math::Vector3d scale = this->WorldScale();

for (size_t i = 0; i < this->ogreNode->numAttachedObjects(); i++)
Expand Down