CCTMXLayer and Null pointer exception when calling setDepthBufferFormat

Hello,

I am new to cocos2d, but am trying to follow the guide referenced in the documentation for CCTMXLayer: http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:tiled_maps

In the section on z-order and the depth buffer, it states that the depth buffer must be explicitly enabled using CCDirector::setDepthBufferFormat, prior to the Director being attached to the openGL view. If I add the setDepthBufferFormat call prior to the CCDirector::setOpenGLView call, then assert in setDepthBufferFormat throws a null pointer exception when it tries to dereference the pointer m_pobOpenGLView in isOpenGLAttached().

When I add a check for a null pointer in isOpenGLAttached, then everything works as expected.

Is this a bug I should report, or am I doing something crazy?

Thanks!

Ben

Thanks. I fix it in this comit https://github.com/cocos2d/cocos2d-x/commit/7b6981878bb6de56fe52d706838909d13a91ead1 Objc will deal this null pointer automatically, but c++ has to write more codes for it.

It just make the function safer. But as you saw in the source, CCDirector::setDepthBufferFormat will check CCDirector::isOpenGLAttached() at first, so besides the null pointer crash, you will get assert(false) here. In other words, setOpenGLView must be invoked before setDepthBufferFormat :slight_smile: