Bug in mipmap generation for non-square textures?

Apr 4, 2013 at 7:36 AM
Hey folks,

I have found a possible bug in mipmap generation for non-square textures. I don't have time to try other cases, but I do see it failing with a 16x64x32 3D texture. The problem appears to be in DirectXTexMipmaps.cpp. The box filtering code uses the following to reduce the texture width in half:
size_t nwidth = width >> 1;
... but when width is already 1, as may happen when reducing non-square textures, the result nwidth will be zero, and then the next call to _StoreScanline will fail with an assertion. I have changed the code to this:
size_t nwidth = width >> 1;
if (nwidth == 0) nwidth = 1;
... and that seems to solve it. I actually searched for any references to "height >> 1" or "width >> 1" and changed all of them.

What do you think? Thanks.

— Mauricio
Coordinator
Apr 4, 2013 at 7:08 PM
Edited Apr 4, 2013 at 7:17 PM
Seems reasonable. I have similar guards elsewhere in the code.

I think this is a bit clearer as a guard and more consistent with elsewhere in the library
size_t nheight = (height > 1) ? (height >> 1) : 1;

size_t nwidth = (width > 1) ? (width >> 1) : 1;
Coordinator
Apr 4, 2013 at 7:23 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Jun 15, 2013 at 8:18 PM
This has been fixed for the June 2013 release