I'm loading an image (a 128x128 TGA file), running iluBuildMipmaps(), and then iterating over the mip levels from 0 to ilGetInteger(IL_NUM_MIPMAPS) calling ilActiveMipmap() on each level. The number of levels is 7 (which seems correct), but when my loop gets to ilActiveMipmap(2), it crashes.
I took a look at the code in il_stack.c, and I think I see what the problem is. It looks like the function is written with the assumption that when it's called, the current image is the base-level mipmap. For an example of this, notice that the function always returns immediately if the requested mip level is 0; that wouldn't be correct if you've already called ilActiveMipmap() to select a different mip level.
Similarly, I suspect that the crash I'm seeing is caused by this same assumption. When I call with mip level 0, it returns immediately. When I call with mip level 1, it correctly sets mip level 1. When I then call with mip level 2, the function attempts to access iCurImage->Mipmaps (and later, iCurImage->Mipmaps->next). I have a sneaking suspicion that iCurImage->Mipmaps is only non-NULL when iCurImage points to the base-level mipmap, and that this is what's causing my crash.
In either case, I think the problem can be fixed by adding some code at the top of the function that resets iCurImage to the base mip level. I also noticed that ilActiveLayer and ilActiveImage() seem to be written very similarly, and may have similar bugs.
Let me know if I'm totally off track or if you're unable to reproduce the problem; I can provide a short sample program if necessary. Thanks!
Log in to post a comment.