cocos2d/cocos2d-x — pull request #2433 by NatWeiss (2013-04-23 22:48:04+00:00)
Title: Fixes bug which caused invalid GL errors

There are certain places that CHECK_GL_ERROR_DEBUG() is called which expect that macro to clear any GL errors. When compiled in release mode (or any mode without COCOS2D_DEBUG==1) this currently doesn't happen because the macro becomes a no-op.

This fixes the macro so it at least clears any GL errors.

Consider CCTexturePVR::createGLTexture(), for example. It sets a bunch of GL parameters, calls CHECK_GL_ERROR_DEBUG() to clear any errors, then proceeds to generate textures and then check for errors manually without the macro. If running in release mode, and setting the parameters does generate an error, then it will be accidentally attributed to the generation of textures, hence causing a false error. The function will think that the texture creation failed when in reality it was from setting the parameters.

I was consistently getting these false errors when loading a PVR texture, unloading it, then loading it again on an older Mac. It took nearly 4 hours of programming time to track down the bug. It was in the call glPixelStorei(GL_UNPACK_ALIGNMENT,1). GL was returning GL_INVALID_ENUM, which is ridiculous, as the parameters are always constant. Nevertheless, GL was giving an error anyway. I suspect this is the reason the CHECK_GL_ERROR_DEBUG() line was added right there, to clear any such false errors.