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)
{
(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))
{
(pNode->*func)();
}
With this, the code works as expecetd.
Regards
Tiger-DS