[vtkusers] vtkAppendFilter, Delete & segfault

Obada Mahdi omahdi at gmx.de
Thu Dec 28 12:34:16 EST 2006


Hi Burlen!

On 12/28/06, Burlen <burlen at apollo.sr.unh.edu> wrote:
> I have a situation where I'm processing chunks of a data set and using the
> append filter to combine the result into another dataset. The chunks are
> passed into a subroutine where the processing and appending takes place. the
> append filter is new'd in the subtroutine, however if I delete the append
> filter then I get a segfault during any later opperations on the resulting
> dataset.

This sounds like a reference counting issue.  In fact, when obtaining
an instance by calling GetOutput() on an algorithm, the reference
count is not incremented automatically.  Thus, deleting the "merger"
instance will effectively delete that output instance as well.  To
keep the algorithm output around, try to insert a call to Register(),
like

>    vtkUnstructuredGrid *result = merger->GetOutput();
> !  result->Register(0);
>    result->Update();

before deleting "merger".


HTH,

Obada


> it's some thing like this:
>
> vtkUnstructuredGrid *processData( vector<vtkUnstructuredGrid *> &chunks )
> {
>    vtkAppendFilter *merger = vtkAppendFilter::New();
>
>    for( each chunk )
>    {
>      //filter & process
>      // .
>      // .
>      // .
>
>      merger->AddInput( filterAndProc->GetOutput() );
>    }
>
>    merger->Update();
>
>    vtkUnstructuredGrid *result = merger->GetOutput();
>    result->Update();
>
>    merger->Delete(); // this ends up causing segfault later!!
>
>    return result;
> }
>
> I'm obviously creating a leak by not Delete'ing the append filter I new'd, so
> the question is why is this happening and what to do? I have a confession to
> make, I'm still using 4.4.



More information about the vtkusers mailing list