Celestia
Celestia copied to clipboard
Incorrect calculation of DDS pixel data size
The size of the pixel data in DDS files is computed incorrectly, leading to the loader attempting to read more bytes than are in the file and triggering the eof()
condition. The reason (at least for square .dds textures in the Celestia Origin files) is that the calculation in the Image
constructor starts with an initial size of 1 rather than 0 (image.cpp line 94), leading to an off-by-one error.
It would be useful to know why this initial value of 1 is being used. I suspect something to do with rectangular textures where division by 2 leads to the smaller dimension being 0 at the last mipmap level, but would need to check.
Mipmap dimensions are always > 0. E.g. if you texture is 16x4, the your mipmaps are 8x2, 4x1, 2x1 and 1x1.