EXC_BAD_ACCESS with gluBuild2DMipmaps

NOTE: I believe the problem to be fixed now. See the next post for an explanation.

Hi guys,

I'm choosing to post this here, on the grounds that the error happens during the gluBuild2DMipmaps call, although I doubt it's actually overly related to OpenGL.

A few weeks (months?) ago, somebody gave me their texture loading class, which I altered slightly (largely just so that it uses mipmaps) and have used a couple of times since. However, in my latest project, I'm quite clearly doing something very wrong, as I get the following two occurrances when using this class:

1. When I Build and Run the program, it attempts to open, and then the debugger opens, displaying an EXC_BAD_ACCESS error, which seems to be somewhere in the middle of the gluBuild2DMipmaps() call.

2. If I place an NSLog() a few lines above this (I originally did this just to check a couple of values without using the debugger), the program Builds and Runs fine, and no error occurs. I don't understand this at all, and it leads me to believe that I'm doing something very wrong, somewhere along the way, but can't seem to figure out where.

Here's the texture loading method, and below it is a link to a screenshot of the debugger window when the program crashes.

EDIT: But wait, I was wrong here too! Keep scrolling down to find out the real reason.

Okay, upon advice from #idevgames and OneSadCookie, I swapped the gluBuild2DMipmaps for a glTexImage2D, and the problem went away. OneSadCookie informs me gluBuild2DMipmaps are "notoriously flaky" and that I should use SGIS_generate_mipmaps instead, so I shall attempt to do that.

That said, I thought gluBuild2DMipmaps had been fixed since 10.4, at least. If it's really the cause of the problem (as opposed to some other random memory trasher elsewhere in the code), then it deserves a bug filed.

Okay, as it turns out I was trying to load my textures too early (I was calling my load texture method in -awakeFromNib).
I have since shifted the call to -prepareOpenGL, and everything works smoothly now.