CCLayer::schedule not working with xcode4 on iphone

CCLayer::schedule not working with xcode4 on iphone
0.0 0


Hi everybody,

I’m working on a project using Cocos2d-x for Iphone using xcode4.
Recently I noticed that the CCLayer::schedule function does not work correctly (the callback function is never called) when developing on the Iphone.
However it worked on the Iphone-Simulator and with the x86-target under Windows. To be precise it doesn’t work when using xcode4 with the llvm compiler 2.0 on an arm target.

After some investigation i suppose this is a bug within clang, not cocos2d-x.

Anyway I decided to post a workarround if anyone else runs into the issue.

The problem occurs in:

CCNode::arrayMakeObjectsPerformSelector(CCArray* parray, callbackFunc func)

It seems that when using clang the folowing statement always evaluates to false and the callback never gets called:

if (pNode && func)

After some testing I found out that arm-code generated by clang always evaluates a function-pointer to false if it’s alone in an if-clause, even if the function pointer is not null.

To fix this problem just change the above sentence to:

if (pNode && (func != NULL))

With this, the code works as expecetd.



I commited your fix into master repository. And will be published with the next version 0.8.4.
Thanks very much!


Hi all,

just found the same issue in CCScheduler::scheduleSelector()

In CCScheduler.cpp, Line 209
it should be

assert(pfnSelector != NULL); 

instead of


I hope Xcode 4.2 and Clang 3.0 will fix this problem

Best regards


Seems to be Scheduler-Day :slight_smile:

The same issue on line 117

 if (m_pfnSelector) 

should be

 if (m_pfnSelector != NULL) 

to work with clang 2.0 on iphone



Oh, it is so bad. I think we should review all the codes, and change all the usage.
#531 is created for the issue.