Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLException: out of memory on large project #54

Open
gazuko opened this issue Dec 26, 2011 · 1 comment
Open

GLException: out of memory on large project #54

gazuko opened this issue Dec 26, 2011 · 1 comment

Comments

@gazuko
Copy link

gazuko commented Dec 26, 2011

I have a project with 17 scenes and approximately 40Mb images. On every scene is about 10-20 Sprites with animation.
If i change scenes from first to last and back - application (device - Samsung Galaxy Tab 10.1, Android 3.2) have a dumped and closed.

I set
mGLSurfaceView.setDebugFlags(CCGLSurfaceView.DEBUG_CHECK_GL_ERROR);
in Activity, and see in LogCat, that is error:
12-26 22:05:45.690: ERROR/AndroidRuntime(11013): FATAL EXCEPTION: GLThread 10
12-26 22:05:45.690: ERROR/AndroidRuntime(11013): android.opengl.GLException: out of memory
12-26 22:05:45.690: ERROR/AndroidRuntime(11013): at android.opengl.GLErrorWrapper.checkError(GLErrorWrapper.java:62)
12-26 22:05:45.690: ERROR/AndroidRuntime(11013): at android.opengl.GLErrorWrapper.glDrawArrays(GLErrorWrapper.java:258)
12-26 22:05:45.690: ERROR/AndroidRuntime(11013): at org.cocos2d.nodes.CCSprite.draw(CCSprite.java:915)
12-26 22:05:45.690: ERROR/AndroidRuntime(11013): at org.cocos2d.nodes.CCNode.visit(CCNode.java:740)
12-26 22:05:45.690: ERROR/AndroidRuntime(11013): at org.cocos2d.nodes.CCNode.visit(CCNode.java:746)
12-26 22:05:45.690: ERROR/AndroidRuntime(11013): at org.cocos2d.nodes.CCNode.visit(CCNode.java:746)
12-26 22:05:45.690: ERROR/AndroidRuntime(11013): at org.cocos2d.transitions.CCTransitionScene.draw(CCTransitionScene.java:76)
12-26 22:05:45.690: ERROR/AndroidRuntime(11013): at org.cocos2d.nodes.CCNode.visit(CCNode.java:740)
12-26 22:05:45.690: ERROR/AndroidRuntime(11013): at org.cocos2d.nodes.CCDirector.drawCCScene(CCDirector.java:716)
12-26 22:05:45.690: ERROR/AndroidRuntime(11013): at org.cocos2d.nodes.CCDirector.onDrawFrame(CCDirector.java:665)
12-26 22:05:45.690: ERROR/AndroidRuntime(11013): at org.cocos2d.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1245)
12-26 22:05:45.690: ERROR/AndroidRuntime(11013): at org.cocos2d.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1056)

I insert releasing textures in my scenes and CCTextureCache, something like this:

public void removeUnusedTextures() {
    HashMap<String, Integer> tempSet = (HashMap<String, Integer>) _texturesRefCount.clone();
    for (String key : tempSet.keySet()){
        String nKey = key;
    if (_texturesRefCount.get(nKey) <= 0){
            WeakReference<CCTexture2D> texWR = textures.get(nKey);
            if (texWR != null){
                CCTexture2D tex = texWR.get();
                if (tex != null){
                    tex.releaseTexture(CCDirector.gl);
                }
            }
            textures.remove(nKey);
            _texturesRefCount.remove(nKey);
        }
    }

}
And call it before scene transitions do. Size of CCTextureCache.textures hashmap not exceed of 50-60 cached textures.
This is a decrease a chance to application crash and i can do more scene transitions, than before, but i still to get crash after a some time.
_texturesRefCount - is a hashmap, i add it to CCTextureCache and increase/decrease counters for my textures.

I use sources, not a jar. Also i see all issues on this subject there and in other places, and try some solutions - noone was to work correct.

What's right way to release resources between different scenes? Does cocos2d automatically texture release, or i need to release it manually?

@gazuko
Copy link
Author

gazuko commented Dec 27, 2011

Problem is resolved, if i call CCTextureCache.removeAllTextures every time before new scene build. But this is not good way, really?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant