Reommend you drop all use of c++ variable property "..."


#1

I had:

CCFiniteTimeAction* action = CCSequence::create( CCRepeat::create(CCAnimate::create(animation), 1) ,CCCallFunc::create(this, callfunc_selector(RjsCharacter::Stand)) );

Which compiled and ran fine for the ios simulator but compiled and run time failed with a bad access error on my devices.

This was happening because of compiler optimisation failing to interpret CCSequence::create()’s “…” property correctly. Inside of CCSequence::create() it would loop correctly through the while loop in the simulator but loop more than the required times when run on the device. Hence the bad access error.

The solution is to use CCArray:

CCArray* actions = CCArray::create(); actions->addObject(CCRepeat::create(CCAnimate::create(animation), 1)); actions->addObject(CCCallFunc::create(this, callfunc_selector(RjsCharacter::Stand))); CCFiniteTimeAction* action = CCSequence::create(actions);

I would recommend you deprecate all methods that use this property. In my experience the use of the property “, …” is fraught with problems that are beyond the control of the library. It likely requires you to set specific compiler flags in order to get your framework working which generally turns people off. Also, not everyone is going to be able to guess that it was a compile time issue and would likely blame cocos2d-x for not working.


#2

All variable parameter lists must be terminated with NULL, it’s your mistake here.


#3

Really? My bad.

I’ll be sticking with CCArray from now on all the same.

Still, that’s a pretty hideous piece of syntax. I was thinking it was along the same lines as printf…


#4

printf detects the number of expected parameters when parsing string to print (counting %). CCSequence::create() and all other cocos2d-x variadic functions can’t do that same way so they need NULL to be passed as terminator. And I agree that’s potential source of mistakes since compiler won’t detect this, but it’s C way and Obj-C way so cocos2d-x uses it.