[Bug]Ping-pong CCRenderTexture(s) “drifts” after each time of rendering

Found the problem while working on an shader program for some special effects. The original image was drawn to one CCRenderTexture renderTexture0 and then the content of renderTexture0 was drawn into renderTexture1. And then draw back from renderTexture1 to renderTexture0, and over and over again…, just like a ping-pong buffer.
It is expected that the final content of renderTextureX should be the same with original image, because that the texture coordinate is not modified in each shaders. But actually it makes some offset from the original image, resulting in a streak.What stranger, is that it seems to happen only on some specific picture(s), while most other pictures are OK.

The source code is reduced to an useless but enough-to-show-issue version, using only cocos2d-x build-in shader programs. You can just replace the HelloWorld::init() of HelloWorld project with the code and see what happens. And the picture with problem is also posted below.

cocos2d-x version: 2.1rc0-x-2.1.4

bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }

    /////////////////////////////
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    CCTexture2D* sourceImage = CCTextureCache::sharedTextureCache()->addImage("pulsar0.png");
    CCSize size = sourceImage->getContentSize();
    CCRenderTexture* renderTexture0 = CCRenderTexture::create(size.width, size.height);
    CCRenderTexture* renderTexture1 = CCRenderTexture::create(size.width, size.height);

    renderTexture0->beginWithClear(0, 0, 0, 0);
    sourceImage->drawAtPoint(CCPointZero);
    renderTexture0->end();

    for (int i=0; i<100; i++)
    {
        renderTexture1->beginWithClear(0, 0, 0, 0);
        renderTexture0->getSprite()->getTexture()->drawAtPoint(ccp(0, 0));
        renderTexture1->end();

        renderTexture0->beginWithClear(0, 0, 0, 0);
        renderTexture1->getSprite()->getTexture()->drawAtPoint(ccp(0, 0));
        renderTexture0->end();
    }

    renderTexture0->setPosition(ccp(winSize.width/2, winSize.height/2));
    addChild(renderTexture0);

    return true;
}


pulsar0.png (46.2 KB)


bug0.png (50.6 KB)

Hello … it seems we are experiencing the very same problem … I have reported the issue here:

on github

but have no answers … apart from people having the bug. Not really sure cocos is the problem but has I got no feed back at all from them … don’t know what to think.