Projects > cpp > Issues > Bug #3695

We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.

Create Issue on Github

ActionManagerEx::initWithDictionary error cause can not initWithDictionary again

Bug #3695 [Closed]
zzzzzzzzz04 2014-01-14 04:10 . Updated about 10 years ago

in the function “void ActionManagerEx::initWithDictionary”

*actionDic.insert);
*actionDic is unordered_map, this is unordered_map’s insert explain:
Each element is inserted only if its key is not equivalent to the key of any other element already in the container (keys in an unordered_map are unique).

so,when I run a scene,leave later,when I return the scene,*actionDic has have the same name vector now. can not insert success
but,ActionObject is depend on the node,node have release now .so play the action is crash.
actionDic.erase(fileName);
_actionDic.insert(std::pair<std::string, cocos2d::Vector<ActionObject
>>(fileName, actionList));

add erase can resole the issue.

j1230xz 2014-06-04 09:26

Hello,
A little too late but someone might find this use-full.
This problem still bugs me, so i did some research. This is a quick fix:

Add this to ActionManagerEx

void ActionManagerEx::releaseActions(const char* jsonName)
{
    std::string path = jsonName;
    ssize_t pos = path.find_last_of("/");
    std::string fileName = path.substr(pos+1,path.length());

    std::unordered_map>::iterator iter;
    std::list toRemove;
    for (iter = _actionDic.begin(); iter != _actionDic.end(); iter++)
    {
        auto strJsonName = iter->first;
        if(strcmp(strJsonName.c_str(), fileName.c_str()) == 0)
        {
            cocos2d::Vector objList = iter->second;
            objList.clear();
            toRemove.push_back(strJsonName);
        }
    }

    for(auto item : toRemove)
    {
        _actionDic.erase(_actionDic.find(item));
    }
}

Then open CCSGUIReader.cpp and add this
ActionManagerEx::getInstance()->releaseActions(fileName);

on line 970 in WidgetPropertiesReader0300::createWidget method (this is for cocos2d-x 3.0, check Other properties reader for other versions)

Edited!!!
_actionDic.erase(_actionDic.find(item), _actionDic.end());
changed to
_actionDic.erase(_actionDic.find(item));

walzer@cocos2d-x.org 2014-10-08 02:54

Redmine issue system is closed, we are using github issue system instead.

This issue was moved to https://github.com/cocos2d/cocos2d-x/issues/8310

Atom PDF

Status:Closed
Start date:2014-01-14
Priority:Low
Due date:
Assignee:-
% Done:

0%

Category:all
Target version:-