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() ...@@ -41,20 +41,10 @@ vtkImageSliceCollection::~vtkImageSliceCollection()
void vtkImageSliceCollection::AddItem(vtkImageSlice *a) void vtkImageSliceCollection::AddItem(vtkImageSlice *a)
{ {
vtkCollectionElement* elem = new vtkCollectionElement; vtkCollectionElement* elem = new vtkCollectionElement;
elem->Item = a;
// Check if the top item is NULL // Find insertion location according to the layer number
if (this->Top == NULL) vtkCollectionElement *prevElem = 0;
{
this->Top = elem;
elem->Item = a;
elem->Next = NULL;
this->Bottom = elem;
this->NumberOfItems++;
a->Register(this);
return;
}
// Insert according to the layer number
int layerNumber = a->GetProperty()->GetLayerNumber(); int layerNumber = a->GetProperty()->GetLayerNumber();
for (vtkCollectionElement *indexElem = this->Top; for (vtkCollectionElement *indexElem = this->Top;
indexElem != 0; indexElem != 0;
...@@ -63,23 +53,29 @@ void vtkImageSliceCollection::AddItem(vtkImageSlice *a) ...@@ -63,23 +53,29 @@ void vtkImageSliceCollection::AddItem(vtkImageSlice *a)
vtkImageSlice* tempImage = static_cast<vtkImageSlice*>(indexElem->Item); vtkImageSlice* tempImage = static_cast<vtkImageSlice*>(indexElem->Item);
if (layerNumber < tempImage->GetProperty()->GetLayerNumber()) if (layerNumber < tempImage->GetProperty()->GetLayerNumber())
{ {
// The indexElem item's layer number is larger, so swap break;
// 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;
} }
prevElem = indexElem;
}
// 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;
} }
//End of list found before a larger layer number
elem->Item = a;
elem->Next = NULL;
this->Bottom->Next = elem;
this->Bottom = elem;
this->NumberOfItems++; this->NumberOfItems++;
a->Register(this); 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