Do not assume that LastCell initializes to -1

If an `ArrayHandle` of `LastCell`s is created, then the contents will be
garbage. Just check to make sure that it is valid.
This commit is contained in:
Kenneth Moreland 2022-08-05 12:55:45 -06:00
parent 5d78780f6e
commit bbdfd3d52b
2 changed files with 4 additions and 4 deletions

@ -107,7 +107,7 @@ public:
cellId = -1;
//Check the last cell.
if (lastCell.CellId != -1)
if ((lastCell.CellId >= 0) && (lastCell.CellId < this->CellSet.GetNumberOfElements()))
{
if (this->PointInCell(point, lastCell.CellId, parametric) == vtkm::ErrorCode::Success)
{
@ -117,7 +117,7 @@ public:
}
//Check the last leaf node.
if (lastCell.NodeIdx != -1)
if ((lastCell.NodeIdx >= 0) && (lastCell.NodeIdx < this->Nodes.GetNumberOfValues()))
{
const auto& node = this->Nodes.Get(lastCell.NodeIdx);
VTKM_ASSERT(node.ChildIndex < 0); //should be a leaf node.

@ -174,7 +174,7 @@ public:
{
vtkm::Vec3f pc;
//See if point is inside the last cell.
if (lastCell.CellId != -1 &&
if ((lastCell.CellId >= 0) && (lastCell.CellId < this->CellSet.GetNumberOfElements()) &&
this->PointInCell(point, lastCell.CellId, pc) == vtkm::ErrorCode::Success)
{
parametric = pc;
@ -183,7 +183,7 @@ public:
}
//See if it's in the last leaf.
if (lastCell.LeafIdx != -1 &&
if ((lastCell.LeafIdx >= 0) && (lastCell.LeafIdx < this->CellCount.GetNumberOfValues()) &&
this->PointInLeaf(point, lastCell.LeafIdx, cellId, pc) == vtkm::ErrorCode::Success)
{
parametric = pc;