[vtk-developers] Memory Management & Exception Handling in VTK

Randall Hand randall.hand at gmail.com
Fri Apr 8 16:00:00 EDT 2005


I've been fighting with a nasty memory problem for a few weeks now. I have a 
large dataset (512x128x128) of vector data that I'm trying (for no other 
reason that to say I tried it) to render flow glyphs, one at every vertex. 
Of course, my system doesn't have enough memory for the required geometry of 
a sphere at every datapoint.

I had expected VTK to simply print an error, generate a garbage image, and 
go about it's business. What actually happens is a coredump. I've discovered 
that in Common/vtkDataArrayTemplate.txx, all of the arrays are allocated 
through "new", and subsequently checked to make sure they aren't NULL. While 
this works for "mallocs", most alot of C++ implementations (including the 
MipsPro version on these SGI's) raise a "bad_alloc" exception instead. I 
made the required changes (patch attached to see the changes) to do the same 
thing as the null checks through Try/Catch blocks but I'm saddened to see 
that it still doesn't work.

Alot of the functions, like Allocate, return 1 on success and 0 on failure. 
Unfortunately, I can't see these return values ever being used. Also, alot 
of these functions make invalid assumptions about things working, most 
notably vtkDataArrayTemplate::WritePointer. This function returns 
(this->Array + id), whether this->Array is NULL or valid. This causes later 
segfaults if any of the Resize or Allocate functions failed to allocate the 
memory.

I've done a little work on trying to add the necessary safeties to make 
these conditions "fail gracefully", but it's in alot of classes. 
Unfortunatley, I'm not really well versed in VTK design yet, so I thought I 
would present this to the group. Is anyone at Kitware aware/working on this?
-- 
Randall Hand
http://www.yeraze.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20050408/8543fabe/attachment.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch.txt
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20050408/8543fabe/attachment-0002.txt>


More information about the vtk-developers mailing list