[vtkusers] Unconnected filter(s) causing seg faults
    N Smethurst 
    nick.smethurst at free.fr
       
    Thu Oct 16 08:42:37 EDT 2003
    
    
  
Hi all
I've been writing a program that includes a drag & drop front end to the VTK 
libraries for a while now, and I have noted there is a sometimes a problem 
with unconnected filters.
For example, in the base class PolyDataToPolyDataFilter, the GetInput() 
method used by derived classes looks like this:
vtkPolyData *vtkPolyDataToPolyDataFilter::GetInput()
{
  if (this->NumberOfInputs < 1)
    {
    return NULL;
    }
  return (vtkPolyData *)(this->Inputs[0]);
}
which is good and precautionary. A null pointer is returned if there is no 
input. However, one or more derived classes seem do things like this in 
their execute methods:
void vtkTubeFilter::Execute()
{
  vtkPolyData *input = this->GetInput();
  vtkPolyData *output = this->GetOutput();
  vtkPointData *pd=input->GetPointData();                // BBZZZZZZZ!
  vtkPointData *outPD=output->GetPointData();
  vtkCellData *cd=input->GetCellData();
  ...
i.e. there is no provision for making sure the return value provided by the 
GetInput() method is valid before it is used. Hence, any filter with no 
input will cause a seg fault. Other derived classes have seg fault 
prevention mechanisms:
void vtkTriangleFilter::Execute()
{
  vtkPolyData *input = this->GetInput();
  if (!input)
    {
    return;
    }
Can these checks be included in all execute methods? I am happy to help by 
submit the simple patches implementing them. I have not checked how many 
need doing yet.. possibly there are very few.
Nick
    
    
More information about the vtkusers
mailing list