Bug? CCClippingRect renders all previous stencil nodes from other CCClippingRect instances

Bug? CCClippingRect renders all previous stencil nodes from other CCClippingRect instances
0.0 0


I’m building a custom scroll layer (LayoutScrollLayer extends CCLayer) using CCClippingRect as the mask. Testing just 1 instance of LayoutScrollLayer works exactly as intended. When I deallocate that scroll layer I see the destructors fire for LayoutScrollLayer, it’s CCClippingRect, and that CCClippingRect stencil CCNode.

However, if I create a new scroll layer (which creates a new CCClippingRect) I see a clipped shape that is a composite of both the previous stencil CCNode and the new stencil CCNode. As I create more scroll layers it just keeps adding all the stencils onto each other.

Here’s the code I use to create the CCClippingNode:

LayoutScrollLayer::init(CCNode* stencil, GLfloat alphaThreshold) : Layout()
if (!Layout::init(scheduleUpdate, enableTouch, size))
return false;

if(stencil == NULL) {
stencil = CCSprite::create(“layout/2x2.png”); //For these tests it is using this condition
stencil~~>setPosition(0.f, 0.f);

m_stencil = stencil;
m_clippingNode = CCClippingNode::create;
m_clippingNode~~>setAnchorPoint(ccp(0.f, 0.f));

And this is how I deallocate the CCClippingNode (this destructor fires and watching the address of m_stencil and m_clippingNode I see those destructors fire):


I think the visit() function for CCClippingNode is somehow caching the stencil shape and shares it with all instances of CCClippingNode (although if I change the size of the initial stencil CCNode it will appropriately adjust the clipping space). I also noticed that creating 2 at the same time would make my two scroll layers share the combined clipping shape.

Am I using CCClippingNode improperly? Maybe there is something I need to do in order to split these into different clipping groups?

Any help is appreciated.



P.S. I’m using cocos2d-2.1rc0-x-2.1.3 testing on iOS iphone simulator.


I’ve been struggling with the same bug couple of hours…

It has been fixed in cocos2dx 3.0, just copy the changes: