Bug with scheduler?

Bug with scheduler?
0.0 0


This bug is a weird one. It doesn’t show up in “release mode”, only “debug mode”. When it does show up, it’s makes programs crash bad.

I could say a lot about it, but I think it’s better to say: run the attached sample program using MSVC2008 (please compile it for debug mode first) and check out the bug in action. Although the sample program is a bit weird and doesn’t seem to make any sense, the full program certainly does and has the same problem.

In short it boils down to this:

When you add a custom node (like CCSprite, but anything based on CCNode should do), one that uses scheduleUpdate to update itself, keep a reference to it and replace the current scene + layer, the Cocos2d scheduler will somehow get lost with the objects that are valid and what objects are not. So it’s really the combination of scheduleUpdate and replaceScene that triggers the bug. It’s also got something to do with actions.

The crashing can be fixed by using a custom selector instead (see the attached source files), but the documentation tellls me not to do that.

Well, I’m hoping I’m not being too vague here. The attached program will explain everything. Just run the app, follow the instructions on the screen and enjoy the crash :slight_smile:

CocosSchedulerBug.zip (594.6 KB)


You use scheduleUpdate() in Actor::initWithLayer(), but there is not function named update? What do you want to do? I do not think it is needed to invoke scheduleUpdate().


In the example it’s not needed, indeed :slight_smile: But in my game it is very much needed, so I do have to invoke scheduleUpdate() for my game. And when I do that, the game will crash, which appears to be a bug in Cocos2d-x.

The call to scheduleUpdate() in Actor::initWithLayer() has only one purpose in this example, which is to show the bug in action :slight_smile:
(like I said, the example is not good and odd in many ways, so some thing might not really make any sense - but scheduleUpdate() should definitely just work as far as I know)


I will discuss this case again with Ming when he back to work in next week :slight_smile:


I confirm this bug…
I am using cocos2d-1.0.1-x-0.11.0… (i know its pretty old by now)
The steps to reproduce are:

  1. you are inside SCENE A… and from within this scene you switch to SCENE B using the standard “replaceScene” call
  2. Inside init() function of SCENE B , you call scheduleUpdate (or any custom scheduler) and the code crashes with the stack pointing to :
    “void CCObject::retain(void)
    CCAssert(m_uReference > 0,”reference count should greater than 0“);

I got around this issue by not switching to a scene (SCENE B) but rather a Layer!.This way i could get the scheduler to work which was necessary for my game.
Hope that helps.


inside SCENE B .h file if the class inherits from CCLAyer and not public CCLayer the scheduleUpdate method (written inside Scene B init method) will cause crash