Skip to content

Commit

Permalink
More nullptr checking on Node classes
Browse files Browse the repository at this point in the history
Signed-off-by: Louise Poubel <[email protected]>
  • Loading branch information
chapulina committed Jul 16, 2021
1 parent 87b30ad commit 83c1590
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 8 deletions.
61 changes: 57 additions & 4 deletions ogre/src/OgreNode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ Ogre::SceneNode *OgreNode::Node() const
void OgreNode::Destroy()
{
BaseNode::Destroy();
Ogre::SceneManager *ogreSceneManager = this->scene->OgreSceneManager();
ogreSceneManager->destroySceneNode(this->ogreNode);

if (nullptr != this->scene)
{
Ogre::SceneManager *ogreSceneManager = this->scene->OgreSceneManager();
if (nullptr != ogreSceneManager)
ogreSceneManager->destroySceneNode(this->ogreNode);
}
this->ogreNode = nullptr;
}

Expand All @@ -82,24 +87,36 @@ void OgreNode::SetRawLocalPose(const math::Pose3d &_Pose3d)
//////////////////////////////////////////////////
math::Vector3d OgreNode::RawLocalPosition() const
{
if (nullptr == this->ogreNode)
return math::Vector3d();

return OgreConversions::Convert(this->ogreNode->getPosition());
}

//////////////////////////////////////////////////
void OgreNode::SetRawLocalPosition(const math::Vector3d &_position)
{
if (nullptr == this->ogreNode)
return;

this->ogreNode->setPosition(OgreConversions::Convert(_position));
}

//////////////////////////////////////////////////
math::Quaterniond OgreNode::RawLocalRotation() const
{
if (nullptr == this->ogreNode)
return math::Quaterniond();

return OgreConversions::Convert(this->ogreNode->getOrientation());
}

//////////////////////////////////////////////////
void OgreNode::SetRawLocalRotation(const math::Quaterniond &_rotation)
{
if (nullptr == this->ogreNode)
return;

this->ogreNode->setOrientation(OgreConversions::Convert(_rotation));
}

Expand All @@ -117,12 +134,29 @@ void OgreNode::Load()
//////////////////////////////////////////////////
void OgreNode::Init()
{
Ogre::SceneManager *sceneManager;
sceneManager = this->scene->OgreSceneManager();
if (nullptr == this->scene)
{
ignerr << "Failed to initialize node: scene is NULL" << std::endl;
return;
}

auto sceneManager = this->scene->OgreSceneManager();
if (nullptr == sceneManager)
{
ignerr << "Failed to initialize node: scene manager is NULL" << std::endl;
return;
}

this->ogreNode = sceneManager->createSceneNode(this->name);
if (nullptr == this->ogreNode)
{
ignerr << "Failed to create Ogre node" << std::endl;
return;
}
this->ogreNode->setInheritScale(true);
this->children = OgreNodeStorePtr(new OgreNodeStore);
}

//////////////////////////////////////////////////
NodeStorePtr OgreNode::Children() const
{
Expand All @@ -132,6 +166,9 @@ NodeStorePtr OgreNode::Children() const
//////////////////////////////////////////////////
bool OgreNode::AttachChild(NodePtr _child)
{
if (nullptr == this->ogreNode)
return false;

OgreNodePtr derived = std::dynamic_pointer_cast<OgreNode>(_child);

if (!derived)
Expand All @@ -149,6 +186,9 @@ bool OgreNode::AttachChild(NodePtr _child)
//////////////////////////////////////////////////
bool OgreNode::DetachChild(NodePtr _child)
{
if (nullptr == this->ogreNode)
return false;

OgreNodePtr derived = std::dynamic_pointer_cast<OgreNode>(_child);

if (!derived)
Expand All @@ -159,6 +199,7 @@ bool OgreNode::DetachChild(NodePtr _child)
}

this->ogreNode->removeChild(derived->Node());

return true;
}

Expand All @@ -172,24 +213,36 @@ OgreNodePtr OgreNode::SharedThis()
//////////////////////////////////////////////////
math::Vector3d OgreNode::LocalScale() const
{
if (nullptr == this->ogreNode)
return math::Vector3d();

return OgreConversions::Convert(this->ogreNode->getScale());
}

//////////////////////////////////////////////////
bool OgreNode::InheritScale() const
{
if (nullptr == this->ogreNode)
return false;

return this->ogreNode->getInheritScale();
}

//////////////////////////////////////////////////
void OgreNode::SetInheritScale(bool _inherit)
{
if (nullptr == this->ogreNode)
return;

this->ogreNode->setInheritScale(_inherit);
}

//////////////////////////////////////////////////
void OgreNode::SetLocalScaleImpl(const math::Vector3d &_scale)
{
if (nullptr == this->ogreNode)
return;

this->ogreNode->setScale(OgreConversions::Convert(_scale));
}

Expand Down
57 changes: 53 additions & 4 deletions ogre2/src/Ogre2Node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ Ogre::SceneNode *Ogre2Node::Node() const
void Ogre2Node::Destroy()
{
BaseNode::Destroy();
Ogre::SceneManager *ogreSceneManager = this->scene->OgreSceneManager();
ogreSceneManager->destroySceneNode(this->ogreNode);

if (nullptr != this->scene)
{
Ogre::SceneManager *ogreSceneManager = this->scene->OgreSceneManager();
if (nullptr != ogreSceneManager)
ogreSceneManager->destroySceneNode(this->ogreNode);
}
this->ogreNode = nullptr;
}

Expand All @@ -89,24 +94,36 @@ void Ogre2Node::SetRawLocalPose(const math::Pose3d &_Pose3d)
//////////////////////////////////////////////////
math::Vector3d Ogre2Node::RawLocalPosition() const
{
if (nullptr == this->ogreNode)
return math::Vector3d();

return Ogre2Conversions::Convert(this->ogreNode->getPosition());
}

//////////////////////////////////////////////////
void Ogre2Node::SetRawLocalPosition(const math::Vector3d &_position)
{
if (nullptr == this->ogreNode)
return;

this->ogreNode->setPosition(Ogre2Conversions::Convert(_position));
}

//////////////////////////////////////////////////
math::Quaterniond Ogre2Node::RawLocalRotation() const
{
if (nullptr == this->ogreNode)
return math::Quaterniond();

return Ogre2Conversions::Convert(this->ogreNode->getOrientation());
}

//////////////////////////////////////////////////
void Ogre2Node::SetRawLocalRotation(const math::Quaterniond &_rotation)
{
if (nullptr == this->ogreNode)
return;

this->ogreNode->setOrientation(Ogre2Conversions::Convert(_rotation));
}

Expand All @@ -124,9 +141,25 @@ void Ogre2Node::Load()
//////////////////////////////////////////////////
void Ogre2Node::Init()
{
Ogre::SceneManager *sceneManager;
sceneManager = this->scene->OgreSceneManager();
if (nullptr == this->scene)
{
ignerr << "Failed to initialize node: scene is NULL" << std::endl;
return;
}

auto sceneManager = this->scene->OgreSceneManager();
if (nullptr == sceneManager)
{
ignerr << "Failed to initialize node: scene manager is NULL" << std::endl;
return;
}

this->ogreNode = sceneManager->createSceneNode();
if (nullptr == this->ogreNode)
{
ignerr << "Failed to create Ogre node" << std::endl;
return;
}
this->ogreNode->setInheritScale(true);
this->children = Ogre2NodeStorePtr(new Ogre2NodeStore);
}
Expand All @@ -140,6 +173,9 @@ NodeStorePtr Ogre2Node::Children() const
//////////////////////////////////////////////////
bool Ogre2Node::AttachChild(NodePtr _child)
{
if (nullptr == this->ogreNode)
return false;

Ogre2NodePtr derived = std::dynamic_pointer_cast<Ogre2Node>(_child);

if (!derived)
Expand Down Expand Up @@ -184,6 +220,7 @@ bool Ogre2Node::DetachChild(NodePtr _child)
}

this->ogreNode->removeChild(derived->Node());

return true;
}

Expand All @@ -197,24 +234,36 @@ Ogre2NodePtr Ogre2Node::SharedThis()
//////////////////////////////////////////////////
math::Vector3d Ogre2Node::LocalScale() const
{
if (nullptr == this->ogreNode)
return math::Vector3d();

return Ogre2Conversions::Convert(this->ogreNode->getScale());
}

//////////////////////////////////////////////////
bool Ogre2Node::InheritScale() const
{
if (nullptr == this->ogreNode)
return false;

return this->ogreNode->getInheritScale();
}

//////////////////////////////////////////////////
void Ogre2Node::SetInheritScale(bool _inherit)
{
if (nullptr == this->ogreNode)
return;

this->ogreNode->setInheritScale(_inherit);
}

//////////////////////////////////////////////////
void Ogre2Node::SetLocalScaleImpl(const math::Vector3d &_scale)
{
if (nullptr == this->ogreNode)
return;

this->ogreNode->setScale(Ogre2Conversions::Convert(_scale));
}

Expand Down

0 comments on commit 83c1590

Please sign in to comment.