mhamon1992 / cocos2d-android-1

Automatically exported from code.google.com/p/cocos2d-android-1
0 stars 0 forks source link

Game freeze issue on samsung #72

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Trying to play game continuously
2.
3.

What is the expected output? What do you see instead?
It should run with proper FPS

What version of the product are you using? On what operating system?
latest one which is there on today 27th may 2011

Please provide any additional information below.
I am using multiple layers which are being added and removed as game screen 
changes. There are also lots of animations and schedulers inside game. But I am 
removing and stopping them as I remove parent layer which contains them. Please 
can anyone help me to find our possible cause? Any way to find leaks or root 
cause?
Thanks in advance.

Original issue reported on code.google.com by rajnimge...@gmail.com on 28 May 2011 at 10:50

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hi, Thanks for reply.
No its not like issue 77.
Let me explain what I am using in my game.
1) GameLayer:
I have taken array of sprites as member variable(to get access during gameplay) 
to this CCLayer class and did addChild all this sprites. There are many 
animations added to some sprites too.
2) extraGameLayer: This CCLayer I used to addChild to GameLayer at some 
particular time as they are diff play as popup game. This also have member 
spritearray and animations too.
3) I add this extraGameLayer to and from GameLayer manytime depending on 
situation.

Initially it works fine but after playing for 20-25 mins it starts lagging. At 
some point it freezes and crash which will cause restart of device. I am using 
Samsung Pop, Ace, Galaxy devices to test.
In Log its showing unable to allocate memory. So somewhere memory is leaking.
Please can you advice some tips to avoid this?
Thank you.

Original comment by rajnimge...@gmail.com on 17 Jun 2011 at 5:17

GoogleCodeExporter commented 8 years ago
Possible cause:

Are you frequently creating/destroying other Sprites/Nodes to 
GameLayer/extraGamelayer?

I noticed that CCNode.cleanup() doesn't seem to be overridden in CCSprite ( and 
CCLabel, etc) so the texture is never released as in issue 83:
http://code.google.com/p/cocos2d-android-1/issues/detail?id=83

Original comment by wopstic...@gmail.com on 28 Jun 2011 at 6:09

GoogleCodeExporter commented 8 years ago
Hi,
Thanks for this information.
Yes you are right, I am doing addChild, removeChild, many CCSprites and 
CCLabels as my level changes.
Each lavel contains many sublevels which also having same addChild and 
removeChild calls to their member CCSprites and CCLabels.
Can you provide me any fix or help how to overcome this or to use anyother 
techniques as as of now its leaking memory if we play continuously.
One thing I did is to load all sprites onetime at starting of game and never 
remove them but it takes lots of redundant code and uses more memory allocated 
as all images are loaded even if they are not needed.
Thanks.

Original comment by rajnimge...@gmail.com on 29 Jun 2011 at 4:50

GoogleCodeExporter commented 8 years ago
I tried this myself... i.e. creating and removing 4 large sprites every frame, 
but the garbage collector handled it perfectly - after 15 minutes I gave up. 
Are you adding lots of *different* sprites? i.e. multiple sprite sheets or 
files for background/ground/sky sections for each level?

Here's the code I thought about patching into CCSprite, but if you have say 5 
happyface sprites on screen, and call   removechild(happyFace[0], true); with 
the code, it releases the texture for all happyfaces, even if they don't come 
from
the same sprite sheet. The others are just drawn as blank white squares since 
the texture is loaded only once, but drawn many times.

    @Override
    public void cleanup() {
        super.cleanup();
        if ( texture_ != null && CCDirector.gl != null) texture_.releaseTexture(CCDirector.gl);

    }

Maybe try making a function like this...  then when you're removing sprites 
(before adding new copies of the same thing),
and between levels. I.e. when you removeChild(child) on everything, try calling 
child.releaseMyTextures(); first?
Essentially, just don't call this function when there might be something with 
the same texture still on screen.

    public void releaseMyTextures(){

        if ( texture_ != null && CCDirector.gl != null) texture_.releaseTexture(CCDirector.gl);     

    }

Let me know if this works.
Also, check the issue I posted last time if your labels are changing/updated 
frequently, it's a one-line fix.

J

Original comment by wopstic...@gmail.com on 29 Jun 2011 at 2:15

GoogleCodeExporter commented 8 years ago
Hi,
Thanks for reply.
Yes I am adding lots of *different* sprites? i.e. multiple sprite sheets or 
files for background/ground/sky sections for each level.
And I am also using timer label to show current time count which is called in 
each frame.

I am adding two fixes suggested by you.
I will let you know if there is any improvement.
Thanks.

Original comment by rajnimge...@gmail.com on 30 Jun 2011 at 8:24

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
The first function (cleanup override )will actually make things worse...
Try just calling the second one at the end of a level, or when you're sure 
there are no identical sprites also on screen, and try the CCLabel fix.

Original comment by wopstic...@gmail.com on 30 Jun 2011 at 8:55

GoogleCodeExporter commented 8 years ago
Hi,
I am little confused.
Can you please let me know where should I put below function and from where to 
call?
 public void releaseMyTextures(){

        if ( texture_ != null && CCDirector.gl != null) texture_.releaseTexture(CCDirector.gl);     

    }

WHAT I DID IS...
added two functions in CSprite.java
 //##CHANGE_30062011
    @Override
    public void cleanup() {
        super.cleanup();
        if ( texture_ != null && CCDirector.gl != null) texture_.releaseTexture(CCDirector.gl);
     }
  //##CHANGE_30062011
    public void releaseMyTextures(){

        if ( texture_ != null && CCDirector.gl != null) texture_.releaseTexture(CCDirector.gl);     

    }

And modified removeChild in CCSprite.java to call releaseMyTextures as shown 
below:
public void removeChild(CCNode node, boolean doCleanup) {

        //##CHANGE_30062011
        releaseMyTextures();

        if( usesSpriteSheet_ ) {
            CCSprite sprite = (CCSprite) node;
            spriteSheet_.removeSpriteFromAtlas(sprite);
        }

        super.removeChild(node, doCleanup);

        hasChildren_ = (children_.size() > 0);
    }

Is this correct?
Please let me know if its wrong and how to fix it.
Thanks.

Original comment by rajnimge...@gmail.com on 30 Jun 2011 at 12:40