Search code examples
androidopengl-esshadercocos2d-x

Shaders are not working in android device when the device goes to lock mode and resumed


First time i am developing android app with cocos2d-2.0-x-2.0.4 on Samsung GT-N8000, so help me if anyone having idea on this topic .

Everything works fine with shaders on this device but I found error when the device goes to lock mode and unlocked.


Solution

  • Ya. We had the same problem. Whatever the custom shaders added to the 'shadercache' doesn't work once app goes to background and resumed from their. Just try to reset the your custom shaders and add a new shader in its place.

    For more info check CCShaderCache::reloadDefaultShaders() which is called called app resume.

      CCGLProgram * program = CCShaderCache::sharedShaderCache()->programForKey("customshader");
       //reset the old
        if(program)
            program->reset();
    
    {
        CCGLProgram * p = new CCGLProgram();
        .....
        .....
        p->updateUniforms();
        //add new shader
        CCShaderCache::sharedShaderCache()->addProgram(p, "customshader");
        p->release();
    
    }