I am using VTK-8.1.0 and attempting to create subclass of vtkMappedDataArray for use with non-AOS data. I used vtkCPExodusIINodalCoordinatesTemplate as a guide.
My subclass is being used to represent vtkStructuredGrid coordinates.
When I attempt to use vtkDataSetWriter to serialize the vtkStructuredGrid to a string, my process crashes.
The crash is occurring in vtkDataWriter::WriteArray
float *s=GetArrayRawPointer( data, static_cast<vtkFloatArray *>(data)->GetPointer(0), isAOSArray);
Question: When isAOSArray is false, why would you even want to attempt the cast to vtkFloatArray and call GetPointer on it?
It ends up calling vtkAOSDataArrayTemplate::GetPointer(), which attempts to dereference it’s Buffer object which is NULL.
In some weird instances during my testing, the vtkAOSDataArrayTemplate’s Buffer isn’t NULL, but simply a bad pointer, so the call succeeds, but the bad pointer doesn’t matter because it isn’t being used due to isAOSArray being false.
Second problem is in GetArrayRawPointer:
vtkSOADataArrayTemplate<T>* typedArray = vtkSOADataArrayTemplate<T>::SafeDownCast(array); typedArray->ExportToVoidPointer(data);
The SafeDownCast fails for my subclass of vtkMappedDataArray, returning null for typedArray, but typedArray is then dereferenced without a check.
(Note: this problem has been fixed in VTK-9, which added a guard for valid typedArray before dereferencing, so that’s an easy patch I can apply to prevent the crash.)
The problem remains that without a successful SafeDownCast there is no way for the vtkDataWriter to write the data contained in my class.
I tried modifying GetArrayRawPointer to forgo the SafeDownCast, and simply call
I re-implemented ExportToVoidPointer for my class, so this change works, but not sure if this will have unforseen consequences.
Is there something that I’ve missed that would allow the vtkMappedDataArray subclass to work correctly with vtkDataWriter?