CCBReader cannot bind variables when dealing with a ccbi that has some sub-ccbis


#1

I have a ccbi (Accbi, javaScript Controlled) , which contains two sub ccbis( Bccbi1, Bccbi2); each sub ccbis has its own child nodes which I want to link to Accbi( so they are “Owner var”, e.g. Bccbi1 has a node b1n01, Bccbi2 has a node b2n01, and their Code Connections is “Owner var”); When I use lua to load “Accbi”, there is an error says :

Cocos2d: [LUA-print] LUA ERROR: ASSERT FAILED ON LUA EXECUTE: index out of range in objectAtIndex()

Cocos2d: [LUA-print] stack traceback:
    ...-46E6-BE93-67BA70EDA909/Card-Battle.app/script/hello.lua:6: in function <...-46E6-BE93-67BA70EDA909/Card-Battle.app/script/hello.lua:3>
    [C]: in function 'objectAtIndex'
    [string "CCBReaderLoad.lua"]:39: in function 'CCBReaderLoad'

I debug the project, and track the source code, I found there are some bugs in the libs/extensions/CCBReader/CCnodeLoader.ccp#parsePropTypeCCBFile;

       CCBReader * ccbReader = new CCBReader(pCCBReader);
       ....
        CCArray *ownerOutletNames = ccbReader->getOwnerOutletNames();             //#place ONE
        CCArray *ownerOutletNodes = ccbReader->getOwnerOutletNodes();    
        if (NULL != ownerOutletNames && ownerOutletNames->count() > 0 &&
            NULL != ownerOutletNodes && ownerOutletNodes->count() > 0)
        {
            assert(ownerOutletNames->count() == ownerOutletNodes->count());
            int nCount = ownerOutletNames->count();
            for (int i = 0 ; i < nCount; i++) {                                     //#place TWO
                pCCBReader->addOwnerOutletName((dynamic_cast(ownerOutletNames->objectAtIndex(i)))->getCString());  
                pCCBReader->addOwnerOutletNode(dynamic_cast(ownerOutletNodes->objectAtIndex(i)) );
            }
        }

if track the constructor of CCBReader, will find that the ccbReader~~>mOwnerCallbackNodes == pCCBReader~~>mOwnerCallbackNodes;
but ccbReader~~>mOwnerCallbackNames != pCCBReader~~>mOwnerCallbackNames;
So the following lines may be wrong:

   pCCBReader->addOwnerOutletName((dynamic_cast(ownerOutletNames->objectAtIndex(i)))->getCString());
   pCCBReader->addOwnerOutletNode(dynamic_cast(ownerOutletNodes->objectAtIndex(i)) );

The situation is,

  1. loading the 1st child Bccbi1 after “#place ONE”, the ownerOutletNames is {“b1n01”}, after “#place TWO”, the pCCBReader~~>mOwnerOutletNames is
  2. loading the 2nd child Bccbi2 after “#place ONE”, the ownerOutletNames is , after “#place TWO”, the pCCBReader~~>mOwnerOutletNames is {“b1n01”, “b1n01”, “b2n01”}
    so, “b1n01” has been added twice, it is the problem.

following is the constructor of CCBReader.

// in the header 
std::vector mOwnerCallbackNames;
 CCArray* mOwnerCallbackNodes;
// in the cpp
CCBReader::CCBReader(CCBReader * pCCBReader) ..
{
....
    this->mOwnerOutletNames = pCCBReader->mOwnerOutletNames;
    this->mOwnerOutletNodes = pCCBReader->mOwnerOutletNodes;
    this->mOwnerOutletNodes->retain();
....
}

thanks,
stalendp@gmail.com