vtkTIFFWriter crashes when saving image sequence
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
When trying to save a vtkImageData object as a set of TIFF images, vtkTIFFWriter crashes. This example (in Java) will cause the crash:
vtkTIFFWriter writer = new vtkTIFFWriter(); writer.SetCompressionToNoCompression(); writer.SetFilePrefix(fileName); writer.SetFilePattern("%s%04d.tif"); writer.SetFileDimensionality(2);
// Gets 3D volume of unsigned shorts vtkImageData stack = generateStack(); writer.SetInput(stack); writer.Write();
The problem is that the TIFF writer always tries to use the file name passed through SetFileName() when opening the file for writing. If you don't specify a name through SetFileName(), then the file name is a null pointer, causing a crash. If you do call SetFileName("file.tif"), then you will wind up with on saved file with the name "file.tif", so that is not a solution.
I fixed the crash by modifying the file vtkTIFFWriter.cxx on line 124. It uses the member variable InternalFileName as the source of the file name instead of calling GetFileName() and works correctly. This is the same way vtkPNGWriter and vtkJPGWriter get the file name. The modified file is attached.