Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
......@@ -41,20 +41,10 @@ vtkImageSliceCollection::~vtkImageSliceCollection()
void vtkImageSliceCollection::AddItem(vtkImageSlice *a)
{
vtkCollectionElement* elem = new vtkCollectionElement;
elem->Item = a;
// 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;
}
// 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++;
a->Register(this);
}
......
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