CCCallFuncND Runtime Error - Cocos2DX v.2.2.1

I need help with trying to resolve this issue. The error message I’m getting is:

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.
This is usually a result of calling a function declared with one calling convention with a 
function pointer declared with a different calling convention.

I was writing Unit Test code to Add object to screen then after a delay remove them. As each Test method is invoked I am displaying a CCLabelTTF to show which method was invoked. When I run this code in Eclipse on an Android device I don’t get any runtime errors but on a Win32, I get the above error message about function pointers.
Please advise.

void Test_SBBallMgr::AddTestLabel( const char *labelString )
{
    CCLabelTTF *lbl = CCLabelTTF::create(labelString, "Arial", 18);
    lbl->setAnchorPoint( ccp(0,0) );
    lbl->setPosition( ccp(10, 500) );
    this->addChild(lbl);

    //Function call to remove Label after two seconds
    CCDelayTime *delay2Secs = CCDelayTime::create(2);
    //Line causing issues.....
    CCCallFuncND *removelabel = CCCallFuncND::create(lbl, callfuncND_selector(CCNode::removeFromParentAndCleanup), (void*)true);
    CCSequence *actions = CCSequence::create(delay2Secs, removelabel, NULL);

    this->runAction(actions);
}

Are you sure you are compiling with cdecl calling convention?
And it seems you don’t need to use CCCallFuncND, since there is an action called CCRemoveSelf which does what you need.

UPD. Wait a minute… you can’t call CCNode::removeFromParentAndCleanup this way. This method takes one argument of bool type, but CCCallFuncND is trying to call it with two arguments.

Hi Dot Squid, the default calling convention in Visual Studio 2012 is ‘__cdecl (/Gd)’ so we can rule that out as an issue.

I did some Googling on CCRemoveSelf and got the CCLabelTTF to remove itself after a delayed time. So the code is now working as expected.

Thank you again for your help and quick response.

Here is the working code:

void Test_SBBallMgr::AddTestLabel( const char *labelString )
{
    CCLabelTTF *lbl = CCLabelTTF::create(labelString, "Arial", 18);
    lbl->setAnchorPoint( ccp(0,0) );
    lbl->setPosition( ccp(10, 500) );
    this->addChild(lbl);

    //Function call to remove ccLabel after two seconds
    CCDelayTime *delay2Secs = CCDelayTime::create(2);
    CCSequence *actions = CCSequence::create(delay2Secs, CCRemoveSelf::create(), NULL);

    lbl->runAction(actions);
}

Hi Dot Squid, the default calling convention in Visual Studio 2012 is ‘__cdecl (/Gd)’ so we can rule that out as an issue.

I did some Googling on CCRemoveSelf and got the CCLabelTTF to remove itself after a delayed time. So the code is now working as I wanted it.

Thank you again for your help and quick response.

Here is the working code, in case anyone else is trying to do the same. Googling for help on this topic was not giving me any good sample code. Most of it was old, in complete or for objective-c:

void Test_SBBallMgr::AddTestLabel( const char *labelString )
{
    CCLabelTTF *lbl = CCLabelTTF::create(labelString, "Arial", 18);
    lbl->setAnchorPoint( ccp(0,0) );
    lbl->setPosition( ccp(10, 500) );
    this->addChild(lbl);

    //Function call to remove ccLabel after two seconds
    CCDelayTime *delay2Secs = CCDelayTime::create(2);
    CCSequence *actions = CCSequence::create(delay2Secs, CCRemoveSelf::create(), NULL);

    lbl->runAction(actions);
}