[vtkusers] Unhandled exception at the time of Unregistering vtkSmartPointer

David Doria daviddoria at gmail.com
Sat Jun 9 07:01:34 EDT 2012


On Fri, Jun 8, 2012 at 10:10 PM, cel02000 <cel02000 at yahoo.com> wrote:
> David,
>
> Please find an example below.
>
> int main()
> {
>    vtkPolyData * polyData50 = vtkPolyData::New(); /// Previously, I used
> vtkSmartPointer< vtkPolyData > polyData50; I even did not used New()
> function but with using pointer I have to use it./
>    Read50Files( polyData50 , "c:\\acquisitions_directory" ); /// After this
> line polyData50 does not contain any pointdata./
>    return 0;
> }
>
> int Read50Files( vtkPolyData * polyData50 , char * ) // Previously, I had
> /int Read50Files( vtkSmartPointer< vtkPolyData> & polyData50, char * )/
> {
>    /// reading and appending the data in 50 files./
>    for( int i=0; i<50; i++)
>    {
>        /// polyDataFile is a vtkPolyData dataset which is read from the
> reader./
>        appendFilter->AddInput( polyDataFile );
>    }
>    appendFilter->Update();
>
>    polyData50 = appendFilter->GetOutput(); /// After this line, polyOut has
> the correct number of pointdata, read from 50 files./
>
>    return 0;
> }

That is not a compilable example. There are no includes, appendFilter
is not defined, etc. In fact, I think it misses the critical part of
the problem.

In this line:
polyData50 = appendFilter->GetOutput();

you are assigning a pointer whose memory is "inside" the append filter
to polyData50. When the function returns, the appendFilter is probably
going out of scope so the memory is no longer valid. What you'd need
instead is

polyData50->DeepCopy(appendFilter->GetOutput());

so that polyData50 actually "contains" the data, and it will remain
even after the function returns.

David



More information about the vtkusers mailing list