A problem with sprite shaders

A problem with sprite shaders
0

A problem with sprite shaders.

I was trying to use shaders in the following way:

  1. I have created global GLProgram objects using GLProgram::createWithFilenames function.
  2. When a sprite needs a shader I create a GLProgramState with a global GLProgram object and assign it to the sprite (or use setGLProgram for existing GLProgramState objects).

The problem I encountered is that these GLProgram objects can not exists on its own. If they are not assigned to sprite they get deleted automatically and I am left with dangling pointers.

How can I preserve these GLProgram objects in a way that they would be used when needed?
Or is there another way to store shaders?

Have you tried calling retain() on the GLProgram? You can also add these objects to a cocos2d::Map or cocos2d::Vector, which automatically calls retain()on the object when it’s inserted into the collection.

1 Like

Thank you!
Calling retain() indeed solved the problem!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.