Crash on replaceScene(), retain issue

Crash on replaceScene(), retain issue
0.0 0


Hi again,

Another issue poped into my face, I’ve been on it for a day and a half now.

Basically, I’m in my main menu scene, and I want to go on the house scene when press on a button.
void AppDelegate::changeToScene(CCScene * scene) { CCDirector* director = CCDirector::sharedDirector(); director->replaceScene(scene); }

However, the application crashes in the CCMutableArray class
void replaceObjectAtIndex(unsigned int uIndex, T pObject, bool bDeleteObject = true)

on the line pObject->retain()
// add the ref if (pObject) { pObject->retain(); }

The scene i’m passing to the AppDelegate function is a public subclass of CCScene.
`class HouseScene : public cocos2d::CCScene
virtual ~HouseScene();
bool init();

CC_SYNTHESIZE_READONLY(HouseSceneLayer*, layer, Layer);


And this scene is init in ApplicationDidFinishLaunching in the AppDelegate class
`menuScene = MenuScene::node();

houseScene = HouseScene::node();

// run

What could be causing that crash ? I’ve been playing with virtual retain() and virtual release() in the HouseScene class but it doesn’t seem to make a difference.


@Fabien Roussot
Have you resolved the problem? I don’t find any error in your description.
May be you can paste the real code or some demo that can reproduce the problem.

Sorry for the late reply.


No, I haven’t solved this issue yet.
The project is fairly big, I worked on something else.

I didn’t think I did anything wrong with the code, I shared in case I was simply missing the point.
I was planning to work on the problem today, so hopefully I will be able to give you an update about it later.
If I’m not heading anywhere within the few coming hours, I will share an archive on the project running (well… crashing) on both iOS/Android.

So more information later, whether I find a solution or not.


@Minggo Zhang

Alright, I looked a bit more into it and tried a few other things… and I’m afraid it still doesn’t work.
So I upload my project with this post.
The first seen is the helloworld scene, the button is just suppose to load the next scene instead of closing the app.
I hope you find something to help me, I will continue working on that as I need it to work before moving on.

Thanks in advance,



A bit more info about this issue,

After playing around for a while, I found out that my first scene contains a layer which is retained 3 times, and released once.
However, when comes the time for this layer to be released with the rest of the scene, its m_uReference is suddenly 0 and it fails on the the assert in the release() function
What I don’t understand is that if I retain, instead of release, the layer in the scene desctructor, the m_uReference counter is equal to one, and put to 2 with the added retain().
I’m trying to track where this variable get modified, but without success so far.

I don’t know if it can help figuring out the issue.

The retain instead of release at least allow me to switch between scenes… that will do for the moment, until I have more time to resolve this issue properly.