[vtkusers] "Annoyance" in vtkDataReader using .NET2005
Hentschel, Bernd
hentschel at rz.rwth-aachen.de
Mon Apr 24 08:26:31 EDT 2006
Dear VTK users,
I just discovered something I would call a major annoyance in the
vtkDataReader because it isn't exactly a bug. We use vtkReader/Writer
classes to (de)serialize vtk data via the WriteToOutputString feature.
We recently switched our development to the new VC8 (aka .NET 2005)
compilers and that's when the following issue with vtkDataReader arose:
Trying to read an "empty" VTK-File (either file or string input), i.e.
the representation of an empty vtkPolyData object (no points, no cells,
just the header), our app crashed inside the read operation. The reason
for this seems to be the "new" STL-implementation shipped with .NET2005.
A lot of calls there are using assertions to ensure proper input
parameters. In particular istream::read(*readbuffer,numbytes) now
asserts that the input read pointer be != NULL. This caused the crash
mentioned above, since eventually a NULL pointer is passed to read (in
template <class T> int vtkReadBinaryData(istream *IS, T *data, int
numTuples, int numComp)).
In the "old" STL implementation this was no problem. A NULL-pointer was
only passed to calls which didn't read anything from the istream either,
so in effect nothing was read. We fixed this issue by introducing a
sanity check into vtkReadBinaryData in vtkDataReader.cxx, resulting in
the following code:
<<<<<
template <class T>
int vtkReadBinaryData(istream *IS, T *data, int numTuples, int numComp)
{
//SANITY CHECK TO PREVENT READING NONSENSE
if(!data || numComp*numTuples == 0)
{
vtkGenericWarningMacro(<<"Invalid input data for binary read
operation!");
return 0;
}
char line[256];
// suck up newline
IS->getline(line,256);
IS->read((char *)data, sizeof(T)*numComp*numTuples);
if (IS->eof())
{
vtkGenericWarningMacro(<<"Error reading binary data!");
return 0;
}
return 1;
}
>>>>>
We had this problem using 4.2.6 but looking at the source code and the
cvs logs it doesn't seem to be fixed in vtk5 yet. I don't know for sure
if the above fix is appropriate but it suffices our needs. So I thought
I might share this one since it was a bit of a headache to figure out.
Regards,
Bernd
--
Dipl.-Inform. Bernd Hentschel
Virtual Reality Group
Center for Computing and Communication (CCC)
RWTH Aachen University
Seffenter Weg 23,
D-52074 Aachen (Germany)
Fon: (+49) 241 / 80 - 24921
Fax: (+49) 241 / 80 - 22134
mailto:hentschel at rz.rwth-aachen.de
http://www.rz.rwth-aachen.de/vr/
More information about the vtkusers
mailing list