cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.21k stars 7.06k forks source link

Node run action crash randomly with RepeatForever of a Sequence #16373

Open kmenager opened 8 years ago

kmenager commented 8 years ago

I have integrated Cocos in an Android app. I use a NDK Helper which create a sequence from a function like in sample http://cocos2d-x.org/docs/programmers-guide/actions/

// target created before and sel a function
CallFunc *caller = CallFunc::create(sel);
auto action = Sequence::create(caller, nullptr);
target->runAction(action);

When I send to many time this part above (1 called every 16 ms), my app crash with this dump

********** Crash dump: **********
Build fingerprint: 'google/hammerhead/hammerhead:6.0.1/MOB30Y/3067468:user/release-keys'
pid: 10858, tid: 10965, name: Timer-0  >>> com.example.cocos:cocosProcess <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x3
Stack frame #00 pc 0056239c  /data/app/com.example.cocos-1/lib/arm/liblCocos2dcpp.so (_ZN7cocos2d9Scheduler28unscheduleAllWithMinPriorityEi+404): Routine cocos2d::Scheduler::unscheduleAllWithMinPriority(int) at /home/kevin/Projects/Sample/com/example/cocos/../cocos2d/cocos/./base/CCScheduler.cpp:622 (discriminator 3)
Stack frame #01 pc 005621fc  /data/app/com.example.cocos-1/lib/arm/libCocos2dcpp.so (_ZN7cocos2d9Scheduler13unscheduleAllEv+24): Routine cocos2d::Scheduler::unscheduleAll() at /home/kevin/Projects/Sample/com/example/cocos/../cocos2d/cocos/./base/CCScheduler.cpp:584
Stack frame #02 pc 0055ae40  /data/app/com.example.cocos-1/lib/arm/libCocos2dcpp.so (_ZN7cocos2d9SchedulerD2Ev+48): Routine cocos2d::Scheduler::~Scheduler() at /home/kevin/Projects/Sample/com/example/cocos/../cocos2d/cocos/./base/CCScheduler.cpp:266
Stack frame #03 pc 0067ca78  /data/app/com.example.cocos-1/lib/arm/libCocos2dcpp.so (_ZN7cocos2d13ActionManager9addActionEPNS_6ActionEPNS_4NodeEb+6572): Routine cocos2d::ActionManager::addAction(cocos2d::Action*, cocos2d::Node*, bool) at /home/kevin/Projects/Sample/com/example/cocos/../cocos2d/cocos/./2d/CCActionManager.cpp:195
Stack frame #04 pc 004687fc  /data/app/com.example.cocos-1/lib/arm/libCocos2dcpp.so (_ZN7cocos2d4Node9runActionEPNS_6ActionE+224): Routine cocos2d::Node::runAction(cocos2d::Action*) at /home/kevin/Projects/Sample/com/example/cocos/../cocos2d/cocos/./2d/CCNode.cpp:1399
Stack frame #05 pc 003c0e58  /data/app/com.example.cocos-1/lib/arm/libCocos2dcpp.so (_ZN9NDKHelper13handleMessageEP6json_tS1_+404): Routine NDKHelper::handleMessage(json_t*, json_t*) at /home/kevin/Projects/Sample/com/example/cocos/jni/../../NDKHelper/NDKHelper.cpp:164
Stack frame #06 pc 003c10bc  /data/app/com.example.cocos-1/lib/arm/libCocos2dcpp.so (Java_org_cocos2dx_cpp_easyndk_AndroidNDKHelper_CPPNativeCallHandler+372): Routine Java_org_cocos2dx_cpp_easyndk_AndroidNDKHelper_CPPNativeCallHandler at /home/kevin/Projects/Sample/com/example/cocos/jni/../../NDKHelper/NDKHelper.cpp:228
Stack frame #07 pc 00d82fd1  /data/app/com.example.cocos-1/oat/arm/base.odex (offset 0x8ae000) (void org.cocos2dx.cpp.easyndk.AndroidNDKHelper.CPPNativeCallHandler(java.lang.String)+92)
Stack frame #08 pc 00d8363b  /data/app/com.example.cocos-1/oat/arm/base.odex (offset 0x8ae000) (void org.cocos2dx.cpp.easyndk.AndroidNDKHelper.SendMessageWithParameters(java.lang.String, org.json.JSONObject)+326)
Stack frame #09 pc 012b4293  /data/app/com.example.cocos-1/oat/arm/base.odex (offset 0x8ae000) (void com.example.cocos.CocosPresenter.sendData()+926)
Stack frame #10 pc 012b3ec9  /data/app/com.example.cocos-1/oat/arm/base.odex (offset 0x8ae000) (void com.example.cocos.CocosPresenter.access$000(com.example.cocos.CocosPresenter)+76)
Stack frame #11 pc 00c81517  /data/app/com.example.cocos-1/oat/arm/base.odex (offset 0x8ae000) (void com.example.cocos.CocosPresenter$1.run()+114)
Stack frame #12 pc 72fea1d7  /data/dalvik-cache/arm/system@framework@boot.oat (offset 0x1ec9000)

I try with different frequency like 1 every seconds and I have the same problem.

I guess the error provide from the autorelease from a node. Any help for this problem ?

Thanks

minggo commented 8 years ago

Could you please provide a test case for it?

kmenager commented 8 years ago

@minggo I have the same issue on iOS, but with more details.

In CCActionInterval.cpp

void RepeatForever::startWithTarget(Node* target)
{
    ActionInterval::startWithTarget(target);
    _innerAction->startWithTarget(target); // stop here with EXC_BAD_ACCESS (code=1, address=0x3a)
}
screen shot 2016-09-05 at 10 47 27

Object is not null (_innerAction, target, etc...)

The code is :

_moveUp = MoveTo::create(timeUp, Vec2(_width / 2,  top));
_moveDown = MoveTo::create(timeDown, Vec2(_width / 2,  _bottomBorder + MARGIN_LINES));
auto callBackUp = CallFunc::create([&]() {
        _actionLabel->setString("up");
});
auto callBackDown = CallFunc::create([&]() {
    _actionLabel->setString("down");
});
seq = Sequence::create(callBackDown, _moveDown, callBackUp, _moveUp, NULL);
_sprite->runAction(RepeatForever::create(seq));
kmenager commented 8 years ago

@minggo up ?

minggo commented 8 years ago

@kmenager sorry, i am busy these days. @slackmoehrle could you please help to reproduce it? Thanks.

kmenager commented 8 years ago

@minggo @slackmoehrle I try to debug this code, but I have a random crash which is really hard to debug. The main sigsegv error is SEGV_MAPERR. Generally, it happen because the scheduler destructor is called (I guess the garbage collector is the main reason)

signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x3
Routine cocos2d::Scheduler::unscheduleAllWithMinPriority(int) at /cocos2d/cocos/./base/CCScheduler.cpp:622 (discriminator 3)
Routine cocos2d::Scheduler::unscheduleAll() at /cocos2d/cocos/./base/CCScheduler.cpp:584
Routine cocos2d::Scheduler::~Scheduler() at /cocos2d/cocos/./base/CCScheduler.cpp:266
Routine cocos2d::ActionManager::addAction(cocos2d::Action*, cocos2d::Node*, bool) at /cocos2d/cocos/./2d/CCActionManager.cpp:195
Routine cocos2d::Node::runAction(cocos2d::Action*) at ./cocos2d/cocos/./2d/CCNode.cpp:1420
Routine NDKHelper::handleMessage(json_t*, json_t*) at /NDKHelper/NDKHelper.cpp:162

I use this lib NDKHelper with the method

void NDKHelper::handleMessage(json_t *methodName, json_t *methodParams)
{
    if (methodName == NULL) {
        return;
    }

    const char *methodNameStr = json_string_value(methodName);

    for (unsigned int i = 0; i < NDKHelper::selectorList.size(); ++i) {
        if (NDKHelper::selectorList[i].getName().compare(methodNameStr) == 0) {
            Value value = NDKHelper::getValueFromJson(methodParams);

            FuncNV sel = NDKHelper::selectorList[i].getSelector();
            Node *target = NDKHelper::selectorList[i].getTarget();

            CallFuncNV *caller = CallFuncNV::create(sel);
            caller->setValue(value);
            caller->retain();
            if (target) {
                target->runAction(caller);
                caller->release();
            }
            break;
        }
    }
}

I try with the last cocos version 3.13 on different Android device and still have the same issue.