Index: vtkDataArrayTemplate.txx =================================================================== RCS file: /viz/home/rhand/CVSROOT/ezViz/Utilities/VTK/Common/vtkDataArrayTemplate.txx,v retrieving revision 1.1.1.2 diff -u -F^f -r1.1.1.2 vtkDataArrayTemplate.txx --- vtkDataArrayTemplate.txx 9 Feb 2005 16:13:50 -0000 1.1.1.2 +++ vtkDataArrayTemplate.txx 8 Apr 2005 19:08:27 -0000 @@ -79,7 +79,7 @@ int vtkDataArrayTemplate::Allocate(vtkIdType sz, vtkIdType) { this->MaxId = -1; - + if(sz > this->Size) { if(this->Array && !this->SaveUserArray) @@ -92,14 +92,20 @@ this->SaveUserArray = 0; int newSize = (sz > 0 ? sz : 1); - this->Array = new T[newSize]; + try { + this->Array = new T[newSize]; + } catch (std::bad_alloc &ba) { + vtkErrorMacro(<< "Unable to allocate " << sz << " size " << sizeof(T) + << " elements. " << ba.what() ); + this->Array = 0; + return 0; + } if(!this->Array) { return 0; } this->Size = newSize; } - return 1; } @@ -153,7 +159,17 @@ this->MaxId = fa->GetMaxId(); this->Size = fa->GetSize(); this->SaveUserArray = 0; - this->Array = new T[this->Size]; + try { + this->Array = new T[this->Size]; + } catch (std::bad_alloc &ba) { + vtkErrorMacro(<< "Unable to allocate " << this->Size << " bytes. " + << ba.what() ); + this->Size = 0; + this->NumberOfComponents = 0; + this->MaxId = -1; + this->Array = 0; + return; + } memcpy(this->Array, fa->GetVoidPointer(0), this->Size*sizeof(T)); } @@ -205,8 +221,13 @@ this->Initialize(); return 0; } - - newArray = new T[newSize]; + try { + newArray = new T[newSize]; + } catch (std::bad_alloc &ba) { + vtkErrorMacro(<< "Unable to allocate " << newSize << " size " << sizeof(T) + << " elements. " << ba.what() ); + return 0; + } if(!newArray) { vtkErrorMacro("Cannot allocate memory\n"); @@ -252,7 +273,13 @@ return; } - newArray = new T[newSize]; + try { + newArray = new T[newSize]; + } catch (std::bad_alloc &ba) { + vtkErrorMacro(<< "Unable to allocate " << newSize << " size " << sizeof(T) + << " elements. " << ba.what() ); + return; + } if(!newArray) { vtkErrorMacro(<< "Cannot allocate memory\n"); @@ -488,8 +515,8 @@ template void vtkDataArrayTemplate::SetNumberOfValues(vtkIdType number) { - this->Allocate(number); - this->MaxId = number - 1; + if (this->Allocate(number) == 1) + this->MaxId = number - 1; } //----------------------------------------------------------------------------