If I create a vtkDenseArray of pointers, then create a smart pointer to an object, store it in the dense array, then let the smart pointer go out of scope, shouldn't it know that it is still needed in the dense array so it should not delete the memory? I looked at the reference count and it does not increase when the object is added to the array with SetValue.<br>
<br>Here is what I was trying to do:<br><br> vtkSmartPointer<vtkDenseArray<vtkRay*> > array = vtkSmartPointer<vtkDenseArray<vtkRay*> >::New();<br> array->Resize(5,1);<br> <br> for(unsigned int i = 0; i < 5; i++)<br>
{<br> vtkSmartPointer<vtkRay> Ray = vtkSmartPointer<vtkRay>::New();<br> double origin[3] = {0.0, 0.0, 0.0};<br> double direction[3] = {1.0, 0.0, 0.0};<br> Ray->SetOrigin(origin);<br> Ray->SetDirection(direction);<br>
<b>//reference count of Ray here is 1</b><br> array->SetValue(i, 0, Ray);<br><b>//reference count of array->GetValue(i,0) here is 1</b><br> vtkRay* RetrievedRay = array->GetValue(i,0);<br> vtkstd::cout << *(RetrievedRay) << vtkstd::endl;<br>
}<br> <br> for(unsigned int i = 0; i < 5; i++)<br> {<br> vtkRay* RetrievedRay = array->GetValue(i,0);<br> vtkstd::cout << *(RetrievedRay) << vtkstd::endl;<b> //segfault occurs here</b><br> }<br>
<br>Is vtkDenseArray not designed to be used like this?<br><br>Thanks,<br><br>David<br>