Commit cbcf09a8 authored by Ben Boeckel's avatar Ben Boeckel
Browse files

Merge topic 'slice-collection-crash' into release-6.3

* slice-collection-crash:
  16130: Fix inconsistency in vtkImageSliceCollection.
parents d3adb935 a2e13351
......@@ -41,20 +41,10 @@ vtkImageSliceCollection::~vtkImageSliceCollection()
void vtkImageSliceCollection::AddItem(vtkImageSlice *a)
{
vtkCollectionElement* elem = new vtkCollectionElement;
// Check if the top item is NULL
if (this->Top == NULL)
{
this->Top = elem;
elem->Item = a;
elem->Next = NULL;
this->Bottom = elem;
this->NumberOfItems++;
a->Register(this);
return;
}
// Insert according to the layer number
// Find insertion location according to the layer number
vtkCollectionElement *prevElem = 0;
int layerNumber = a->GetProperty()->GetLayerNumber();
for (vtkCollectionElement *indexElem = this->Top;
indexElem != 0;
......@@ -63,23 +53,29 @@ void vtkImageSliceCollection::AddItem(vtkImageSlice *a)
vtkImageSlice* tempImage = static_cast<vtkImageSlice*>(indexElem->Item);
if (layerNumber < tempImage->GetProperty()->GetLayerNumber())
{
// The indexElem item's layer number is larger, so swap
// the new item and the indexElem item.
elem->Item = indexElem->Item;
elem->Next = indexElem->Next;
indexElem->Item = a;
indexElem->Next = elem;
this->NumberOfItems++;
a->Register(this);
return;
break;
}
prevElem = indexElem;
}
//End of list found before a larger layer number
elem->Item = a;
elem->Next = NULL;
this->Bottom->Next = elem;
// Insert the new element into the linked list
if (prevElem == 0)
{
elem->Next = this->Top;
this->Top = elem;
}
else
{
elem->Next = prevElem->Next;
prevElem->Next = elem;
}
// Check if this is the new bottom
if (elem->Next == 0)
{
this->Bottom = elem;
}
this->NumberOfItems++;
a->Register(this);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment