Skip to content

fix (viz): SAxis with zero transform crashes at stop

Description

getTransformNode was ambiguous since it returns the transform node if existing or creates it if it doesn't.

This behaviour is kept, but function was renamed into getOrCreateTransformNode. A pure getter was also created getTransformNode() to return the transform node pointer or nullptr if it doesn't exists.

Add small unit test to test ITransformable functions

All adaptors was updated to call either getOrCreateTransformNode or getTransformNode regarding the case (creation of the node of getting the pointer). This fixes the crash due to Ogre exception "Node already exists" when trying to get a deleted node.

Closes #675 (closed)

How to test it?

To strictly test the fix

Apply this patch temporary & Run Tuto15Matrix

diff --git a/modules/viz/scene3d/adaptor/STransform.cpp b/modules/viz/scene3d/adaptor/STransform.cpp
index 209d99b928..110028804d 100644
--- a/modules/viz/scene3d/adaptor/STransform.cpp
+++ b/modules/viz/scene3d/adaptor/STransform.cpp
@@ -99,9 +99,10 @@ void STransform::updating()
         const auto transform = m_matrix.lock();
         m_ogreTransform = Ogre::Affine3(sight::viz::scene3d::Utils::convertTM3DToOgreMx(transform.get_shared()));
     }
-
-    if(m_ogreTransform == Ogre::Affine3::ZERO)
+    static int i = 0;
+    if( i >= 10 || m_ogreTransform == Ogre::Affine3::ZERO)
     {
+        std::cout << "FORCE REMOVING transformNode" << std::endl;
         m_parentTransformNode->removeChild(m_transformNode);
     }
     else
@@ -123,6 +124,8 @@ void STransform::updating()
     }
 
     this->requestRender();
+
+    i++;
 }

This patch ensures to delete the transformNode after some update (10 or more), UGLY code ONLY for testing.

Without this MR tuto15matrix will crash at stop, it shouldn't with this MR.

To test the whole refactoring

Try on as many applications that contains transform on scene3d as you can.

Edited by Marc SCHWEITZER

Merge request reports