CCClippingNode will raise error "Stencil buffer is not enabled." When your app's first draw use CCClippingNode

I’m using CCClippingNode,

With my test,

In iOS7 and before, everything goes well, in simulator and device.

After I upgrade my XCode to version 6.0, iOS simulator also became iOS8, “Stencil buffer is not enabled.” raised then. My iOS8 device has the same problems.

In AppController.mm, depthFormat is always be setted:

"
EAGLView *__glView = [EAGLView viewWithFrame: [window bounds]
pixelFormat: kEAGLColorFormatRGBA8
depthFormat: GL_DEPTH24_STENCIL8_OES
preserveBackbuffer: NO
sharegroup: nil
multiSampling: NO
numberOfSamples: 0];
"

1 Like

Finally I solved this “issue”.

By do this:

[[UIApplication sharedApplication] setStatusBarHidden: YES];

// Add this line code, force calling resizeFromLayer, which will actually create the render buffer with depth buffer and stencil buffer
[__glView layoutSubviews];

cocos2d::CCApplication::sharedApplication()->run();

This fix is not very elegant, as “layoutSubviews” in apple’s documents said:

"You should not call this method directly. If you want to force a layout update, call the setNeedsLayout method instead to do so prior to the next drawing update. "

I tried “setNeedsLayout” but not works. As my first scene will be drawn immediately.
As a result if your first scene need to use “Stencil Buffer”, a short fix is directly call “layoutSubviews” before CCApplication run.

If this issue can be fixed in cocos2dx, that will be nice.
This problem has bugged me for several days.

2 Likes

Bro, you just saved my life :slight_smile:

I think call the function “layoutIfNeeded” is better