[vtkusers] Unhandled exception at the time of Unregistering vtkSmartPointer

Jochen K. jochen.kling at email.de
Tue Jun 12 02:41:03 EDT 2012


Hi Ahmad,

here is an example which is trying to show what happens using a
vtkSmartPointer. Notes are in the comments.


#include <vtkSmartPointer.h>
#include <vtkDoubleArray.h>

#define PI 3.14159
   
   void myConsumerFunction(vtkDoubleArray* doubleArray) {
      // use your doubleArray or change it
      // but don't use malloc or free on the array!
   }


   void myProducerFunction() {
      const int numberOfValues = 360;
      vtkSmartPointer<vtkDoubleArray> myDoubleArray =
vtkSmartPointer<vtkDoubleArray>::New();
      myDoubleArray->SetNumberOfComponents(1);
      myDoubleArray->SetNumberOfTuples(numberOfValues);
      // fill array
      for(int i = 0; i < numberOfValues; i++)
         myDoubleArray->SetTuple1(i, sin(i/180.*PI));
      myConsumerFunction(myDoubleArray);
   }



   int main(int, char*[])
   {
      myProducerFunction();
      // immediately after myProducerFunction() has returned
      // myDoubleArray is out of scope and is being deleted automatically.
      // There's no need to delete myDoubleArray explicitely anymore
      //...
      // more function calls
      // ...
      return EXIT_SUCCESS;
   }

with kind regards

Jochen


--
View this message in context: http://vtk.1045678.n5.nabble.com/Unhandled-exception-at-the-time-of-Unregistering-vtkSmartPointer-tp5713691p5713775.html
Sent from the VTK - Users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120611/51a678b7/attachment.htm>


More information about the vtkusers mailing list