频繁runaction出现crash

修改的源码:

CCAutoReleasePool 增加--line72 》》》  if(&obj!=0)
CCActionManager 增加--line384 》》》 && _currentTarget->actions!=nullptr

代码如下:想做个字幕滚动的效果:

//step向上滚动,然后恢复原来的位置和大小,并通过回调立刻更改内容
void HelloWorld::step(int select,int line){
	if(isPlaying)
		return;
	isPlaying=true;
	preLine=curLine;
	curLine=line;
	curSelect=select;
	for(int i=0;i<num;i++){
		CCLabelTTF * text = (CCLabelTTF *)getChildByTag(i);

		ScaleTo* scaleTo=ScaleTo::create(0.0f,1.0f);

		if(preSelect+preLine!=select){//快进时..
			if(i!=num-1){
				CCLog("HelloWorld::step###快进###i=%d",i);
				text->runAction(scaleTo);
			}
			else{
				CCLog("HelloWorld::step###快进###i=%d",i);
				text->runAction(CCSequence::create(scaleTo,CCCallFunc::create(this,callfunc_selector(HelloWorld::updateLrc)),NULL));
			}
		}
		else{//正常播放
			CCPoint point = text->getPosition();


			//text->setPosition(ccp(point.x,point.y-2*height));
			MoveTo* moveTo=MoveTo::create(0.1f,Vec2(point.x,point.y+11*fontSize/6+fontSize*(preLine-1)*2));
			Spawn* spawnTo;
			ScaleTo* scaleOut=ScaleTo::create(0.1f,(float)selectFontSize/fontSize);
			ScaleTo* scaleIn=ScaleTo::create(0.1f,(float)fontSize/selectFontSize);
			CCPlace* moveToBack=CCPlace::create(Vec2(point.x,point.y));
			if(i>=2+preLine-1 && i<2+preLine-1+line){//当前选中放大
				spawnTo=Spawn::create(moveTo,scaleOut,NULL);

			}
			else if(i>=1 && i<1+preLine){//上次选中大小恢复
				spawnTo=Spawn::create(moveTo,scaleIn,NULL);

			}
			else{//其他移动
				spawnTo=Spawn::create(moveTo,NULL);

			}
			CCLog("HelloWorld::step###i=%d",i);
			if(i!=num-1){
				text->runAction(CCSequence::create(spawnTo,moveToBack,scaleTo,NULL));
			}
			else{
				curSelect=select;
				text->runAction(CCSequence::create(spawnTo,moveToBack,scaleTo,CCCallFunc::create(this,callfunc_selector(HelloWorld::updateLrc)),NULL));

			}
		}
	}
	
}
void HelloWorld::updateLrc(){
	int j=0;
	std::vector<std::string>::iterator iter=stringVector.begin();

	for(int i=0;i<num;i++){
		CCLabelTTF * text = (CCLabelTTF *)getChildByTag(i);
		text->stopAllActions();
		if(i+curSelect<stringVector.size()){
			text->setString(stringVector[i+curSelect]);
		}
		else{
			text->setString("");
		}
		if(i>1&&i<curLine+1){//除了第一个选中的行,其他要选中的内容
			text->setFontSize(selectFontSize);
		}
		else if(i>=curLine+1){//其他不用选中的行
			text->setFontSize(fontSize);
		}
	}
	preLine=curLine;
	preSelect=curSelect;

	isPlaying=false;//允许继续获取
}

出现的crash不一样,我用ndk-stack查看信息,指向的错误位置,有的是获取actions的代码,有的则是Action调用startWithTarget
类似的情况如下:

//Action调用startWithTarget

signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 56582fe0
Stack frame I/DEBUG   ( 9236):     #00  pc 00048fe0  <unknown>: Unable to open s
ymbol file E:\game\hellogame\proj.android\obj\local\armeabi/<unknown>. Error (22
): Invalid argument
Stack frame I/DEBUG   ( 9236):     #01  pc 0030a403  /data/app-lib/com.konka.mul
timedia-1/libcocos2dcpp.so (cocos2d::Sequence::update(float)+230): Routine cocos
2d::Sequence::update(float) at E:\game\hellogame\proj.android\../cocos2d/cocos/.
/2d/CCActionInterval.cpp:363
Stack frame I/DEBUG   ( 9236):     #02  pc 0030a3b3  /data/app-lib/com.konka.mul
timedia-1/libcocos2dcpp.so (cocos2d::Sequence::update(float)+150): Routine cocos
2d::Sequence::update(float) at E:\game\hellogame\proj.android\../cocos2d/cocos/.
/2d/CCActionInterval.cpp:341
Stack frame I/DEBUG   ( 9236):     #03  pc 0030a319  /data/app-lib/com.konka.mul
timedia-1/libcocos2dcpp.so (cocos2d::ActionInterval::step(float)+190): Routine c
ocos2d::ActionInterval::step(float) at E:\game\hellogame\proj.android\../cocos2d
/cocos/./2d/CCActionInterval.cpp:139 (discriminator 3)
Stack frame I/DEBUG   ( 9236):     #04  pc 0035fd5b  /data/app-lib/com.konka.mul
timedia-1/libcocos2dcpp.so (cocos2d::ActionManager::update(float)+98): Routine c
ocos2d::ActionManager::update(float) at E:\game\hellogame\proj.android\../cocos2
d/cocos/./2d/CCActionManager.cpp:398
Stack frame I/DEBUG   ( 9236):     #05  pc 003372cf  /data/app-lib/com.konka.mul
timedia-1/libcocos2dcpp.so (std::_Function_handler<void (float), void cocos2d::S
cheduler::scheduleUpdate<cocos2d::ActionManager>(cocos2d::ActionManager*, int, b
ool)::{lambda(float)#1}>::_M_invoke(std::_Any_data const&, float)+6): Routine vo
id cocos2d::Scheduler::scheduleUpdate<cocos2d::ActionManager>(cocos2d::ActionMan
ager*, int, bool)::{lambda(float)#1}::operator()(float) const at E:\game\helloga
me\proj.android\../cocos2d/cocos/./base/CCScheduler.h:284
Stack frame I/DEBUG   ( 9236):     #06  pc 0033fcc7  /data/app-lib/com.konka.mul
timedia-1/libcocos2dcpp.so (std::function<void (float)>::operator()(float) const
+14): Routine std::function<void (float)>::operator()(float) const at E:/android
ndk/sources/cxx-stl/gnu-libstdc++/4.8/include/functional:2464
Stack frame I/DEBUG   ( 9236):     #07  pc 003406f7  /data/app-lib/com.konka.mul
timedia-1/libcocos2dcpp.so (cocos2d::Scheduler::update(float)+70): Routine cocos
2d::Scheduler::update(float) at E:\game\hellogame\proj.android\../cocos2d/cocos/
./base/CCScheduler.cpp:852
Stack frame I/DEBUG   ( 9236):     #08  pc 00338d99  /data/app-lib/com.konka.mul
timedia-1/libcocos2dcpp.so (cocos2d::Director::drawScene()+52): Routine cocos2d:
:Director::drawScene() at E:\game\hellogame\proj.android\../cocos2d/cocos/./base
/CCDirector.cpp:269
Stack frame I/DEBUG   ( 9236):     #09  pc 00338ecb  /data/app-lib/com.konka.mul
timedia-1/libcocos2dcpp.so (cocos2d::DisplayLinkDirector::mainLoop()+42): Routin
e cocos2d::DisplayLinkDirector::mainLoop() at E:\game\hellogame\proj.android\../
cocos2d/cocos/./base/CCDirector.cpp:1337
Stack frame I/DEBUG   ( 9236):     #10  pc 002f70c7  /data/app-lib/com.konka.mul
timedia-1/libcocos2dcpp.so (Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeRender+
10): Routine Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeRender at E:\game\hell
ogame\proj.android\../cocos2d/cocos/platform/android/jni/Java_org_cocos2dx_lib_C
ocos2dxRenderer.cpp:16
Stack frame I/DEBUG   ( 9236):     #11  pc 0001dbcc  /system/lib/libdvm.so (dvmP
latformInvoke+112)
Stack frame I/DEBUG   ( 9236):     #12  pc 0004e123  /system/lib/libdvm.so (dvmC
allJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+398)
Stack frame I/DEBUG   ( 9236):     #13  pc 00000214  /dev/ashmem/dalvik-jit-code
-cache (deleted)

或者获取actions

Stack frame I/DEBUG   ( 4315):     #00  pc 0035fd22  /data/app-lib/com.konka.mul
timedia-1/libcocos2dcpp.so (cocos2d::ActionManager::update(float)+41): Routine c
ocos2d::ActionManager::update(float) at E:\game\hellogame\proj.android\../cocos2
d/cocos/./2d/CCActionManager.cpp:386 (discriminator 1)
Stack frame I/DEBUG   ( 4315):     #01  pc 003372cf  /data/app-lib/com.konka.mul
timedia-1/libcocos2dcpp.so (std::_Function_handler<void (float), void cocos2d::S
cheduler::scheduleUpdate<cocos2d::ActionManager>(cocos2d::ActionManager*, int, b
ool)::{lambda(float)#1}>::_M_invoke(std::_Any_data const&, float)+6): Routine vo
id cocos2d::Scheduler::scheduleUpdate<cocos2d::ActionManager>(cocos2d::ActionMan
ager*, int, bool)::{lambda(float)#1}::operator()(float) const at E:\game\helloga
me\proj.android\../cocos2d/cocos/./base/CCScheduler.h:284
Stack frame I/DEBUG   ( 4315):     #02  pc 0033fcc7  /data/app-lib/com.konka.mul
timedia-1/libcocos2dcpp.so (std::function<void (float)>::operator()(float) const
+14): Routine std::function<void (float)>::operator()(float) const at E:/android
ndk/sources/cxx-stl/gnu-libstdc++/4.8/include/functional:2464
Stack frame I/DEBUG   ( 4315):     #03  pc 003406f7  /data/app-lib/com.konka.mul
timedia-1/libcocos2dcpp.so (cocos2d::Scheduler::update(float)+70): Routine cocos
2d::Scheduler::update(float) at E:\game\hellogame\proj.android\../cocos2d/cocos/
./base/CCScheduler.cpp:852
Stack frame I/DEBUG   ( 4315):     #04  pc 00338d99  /data/app-lib/com.konka.mul
timedia-1/libcocos2dcpp.so (cocos2d::Director::drawScene()+52): Routine cocos2d:
:Director::drawScene() at E:\game\hellogame\proj.android\../cocos2d/cocos/./base
/CCDirector.cpp:269
Stack frame I/DEBUG   ( 4315):     #05  pc 00338ecb  /data/app-lib/com.konka.mul
timedia-1/libcocos2dcpp.so (cocos2d::DisplayLinkDirector::mainLoop()+42): Routin
e cocos2d::DisplayLinkDirector::mainLoop() at E:\game\hellogame\proj.android\../
cocos2d/cocos/./base/CCDirector.cpp:1337
Stack frame I/DEBUG   ( 4315):     #06  pc 002f70c7  /data/app-lib/com.konka.mul
timedia-1/libcocos2dcpp.so (Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeRender+
10): Routine Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeRender at E:\game\hell
ogame\proj.android\../cocos2d/cocos/platform/android/jni/Java_org_cocos2dx_lib_C
ocos2dxRenderer.cpp:16
Stack frame I/DEBUG   ( 4315):     #07  pc 0001dbcc  /system/lib/libdvm.so (dvmP
latformInvoke+112)
Stack frame I/DEBUG   ( 4315):     #08  pc 0004e123  /system/lib/libdvm.so (dvmC
allJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+398)
Stack frame I/DEBUG   ( 4315):     #09  pc 00026fe0  /system/lib/libdvm.so
Stack frame I/DEBUG   ( 4315):     #10  pc 0002dfa0  /system/lib/libdvm.so (dvmM
terpStd(Thread*)+76)
Stack frame I/DEBUG   ( 4315):     #11  pc 0002b638  /system/lib/libdvm.so (dvmI
nterpret(Thread*, Method const*, JValue*)+184)
Stack frame I/DEBUG   ( 4315):     #12  pc 00060581  /system/lib/libdvm.so (dvmC
allMethodV(Thread*, Method const*, Object*, bool, JValue*, std::__va_list)+336)
Stack frame I/DEBUG   ( 4315):     #13  pc 000605a5  /system/lib/libdvm.so (dvmC
allMethod(Thread*, Method const*, Object*, JValue*, ...)+20)
Stack frame I/DEBUG   ( 4315):     #14  pc 0005528b  /system/lib/libdvm.so
Stack frame I/DEBUG   ( 4315):     #15  pc 0000d228  /system/lib/libc.so (__thre
ad_entry+72)
Stack frame I/DEBUG   ( 4315):     #16  pc 0000d3c0  /system/lib/libc.so (pthrea
d_create+240)

想试试实现Android的功能,结果掉坑里了。。[s:6][s:6]求各位大侠帮助[s:2][s:2]

终于能发帖了…T_T

我顺手帮你改好了贴子的markdown格式。

至于问题本身,我没有时间看你详细代码了。但是CCAutoReleasePool是内存管理的核心部分,你修改这个地方,导致不该被释放的对象在引擎循环中被干掉了,出现野指针,导致崩溃。我的直觉是这样。

谢谢版主纠正:yum:,我恢复原来的代码然后运行了,也是会遇到_actions[found]->startWithTarget(_target);报invalid argument的情况,请问应该从什么方面考虑原因呢,能否指点一二