소스 검색

Fix segfaults associated with ctkSimplePythonShell tests

* In both "wrappedVTKQInvokableTest.py" and "wrappedVTKSlotTest.py",
a vtkTable was instantiated within python and set to wrapped cpp
instance of either (a) "ctkTestWrappedVTKQInvokable" or (b) "ctkTestWrappedVTKSlot".

Within each on of these classes (a and b), the "Delete" function
was called unconditionally on the MyTable private member. Two problems
were happening:

 - the first instance of vtkTable initially created within the constructor
of classes a and b was leaked.

 - the vtkTable instantiated within python referenced with the "t2"
variable was set to the classes a and b. Then, when python was finalized
it was deleting the object allocated within python. Next, in addition the
Delete function was also called within the destructor of classes a and b.
The pointer being invalid, a seg fault occurred. Using vtkSmartPointer
help us to elegantly address this issue.
Jean-Christophe Fillion-Robin 13 년 전
부모
커밋
d488c63e5d
2개의 변경된 파일8개의 추가작업 그리고 8개의 파일을 삭제
  1. 4 4
      Applications/ctkSimplePythonShell/ctkTestWrappedVTKQInvokable.h
  2. 4 4
      Applications/ctkSimplePythonShell/ctkTestWrappedVTKSlot.h

+ 4 - 4
Applications/ctkSimplePythonShell/ctkTestWrappedVTKQInvokable.h

@@ -25,6 +25,7 @@
 #include <QObject>
 
 // VTK includes
+#include <vtkSmartPointer.h>
 #include <vtkTable.h>
 
 class ctkTestWrappedVTKQInvokable : public QObject
@@ -34,12 +35,11 @@ public:
 
   ctkTestWrappedVTKQInvokable(QObject * newParent = 0) : QObject(newParent)
     {
-    this->MyTable = vtkTable::New();
+    this->MyTable = vtkSmartPointer<vtkTable>::New();
     }
-    
+
   virtual ~ctkTestWrappedVTKQInvokable()
     {
-    this->MyTable->Delete();
     }
 
   /// Example of 'invokable' returning a VTK object
@@ -58,7 +58,7 @@ public:
     }
 
 private:
-  vtkTable * MyTable;
+  vtkSmartPointer<vtkTable> MyTable;
 };
 
 #endif

+ 4 - 4
Applications/ctkSimplePythonShell/ctkTestWrappedVTKSlot.h

@@ -25,6 +25,7 @@
 #include <QObject>
 
 // VTK includes
+#include <vtkSmartPointer.h>
 #include <vtkTable.h>
 
 class ctkTestWrappedVTKSlot : public QObject
@@ -34,12 +35,11 @@ public:
 
   ctkTestWrappedVTKSlot(QObject * newParent = 0) : QObject(newParent)
     {
-    this->MyTable = vtkTable::New();
+    this->MyTable = vtkSmartPointer<vtkTable>::New();
     }
-    
+
   virtual ~ctkTestWrappedVTKSlot()
     {
-    this->MyTable->Delete();
     }
 
 public Q_SLOTS:
@@ -57,7 +57,7 @@ public Q_SLOTS:
     }
 
 private:
-  vtkTable * MyTable;
+  vtkSmartPointer<vtkTable> MyTable;
 };
 
 #endif