[vtkusers] vtkAppendFilter, Delete & segfault

Burlen burlen at apollo.sr.unh.edu
Thu Dec 28 13:08:20 EST 2006


Hi randall, and Obada, thanks for the advise! Both ideas work! it's nice to 
have multiple options. I really appreciate the help
Burlen



 

On Thursday 28 December 2006 12:34 pm, Obada Mahdi wrote:
> 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.

-- 

Burlen Loring
Space Science Center
Institute for the Study of Earth, Oceans, and Space
University of New Hampshire
39 College Road, Durham, NH 03824
Phone: 603-862-1140



More information about the vtkusers mailing list