CCTMXLayer and Null pointer exception when calling setDepthBufferFormat

CCTMXLayer and Null pointer exception when calling setDepthBufferFormat
0.0 0



I am new to cocos2d, but am trying to follow the guide referenced in the documentation for CCTMXLayer:

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. I fix it in this comit 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: