Skip to content
Snippets Groups Projects
Commit 31c41ab5 authored by Sunderlandkyl's avatar Sunderlandkyl Committed by Lucas Givord
Browse files

Fix crash in vtkPointLocator when number of points is changed to zero

When the number of points in the input dataset was set to zero, BuildLocator would be called but the HashTable would not be invalidated.
The FindClosestPoint methods would continue on with the invalid HashTable, resulting in a crash when invalid point IDs were accessed.

Fixed by calling FreeSearchStructure before returning from BuildLocatorInternal so that the HashTable is invalidated.
FreeSearchStructure now also re-initializes variables that are calculated during BuildLocatorInternal so that Bounds/H/Divisions will be consistent for an empty dataset.
Removed vtkErrorMacro when the dataset is empty or has no points since it is a valid input.

(cherry picked from commit c14d87f8)
parent 41b19147
No related branches found
No related tags found
No related merge requests found
......@@ -134,6 +134,13 @@ void vtkPointLocator::FreeSearchStructure()
delete[] this->HashTable;
this->HashTable = nullptr;
}
// The hash table has been invalidated.
// Reset the variables calculated from the dataset to their original values defined in the
// constructor.
vtkMath::UninitializeBounds(this->Bounds);
this->H[0] = this->H[1] = this->H[2] = 0.0;
this->Divisions[0] = this->Divisions[1] = this->Divisions[2] = 50;
}
//------------------------------------------------------------------------------
......@@ -852,15 +859,16 @@ void vtkPointLocator::BuildLocatorInternal()
vtkDebugMacro(<< "Hashing points...");
this->Level = 1; // only single lowest level
// Delete the current hash table values and reset dataset metrics to their original values.
this->FreeSearchStructure();
if (!this->DataSet || (numPts = this->DataSet->GetNumberOfPoints()) < 1)
{
vtkErrorMacro(<< "No points to subdivide");
// Missing datasets and datasets with no points are valid inputs and should not log an error.
// Searching for the closest point id is always -1 for this data.
return;
}
// Make sure the appropriate data is available
this->FreeSearchStructure();
// Size the root bucket. Initialize bucket data structure, compute
// level and divisions.
const double* bounds = this->DataSet->GetBounds();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment