AndEngine:获取SIGSEGV和TouchEventPool活动 [英] AndEngine: Getting a SIGSEGV and TouchEventPool Events
问题描述
我正在开发的Android使用andengine游戏。基本上,我使用的是2 的ArrayList
来存储我的2种类型的精灵。我添加并在运行时去除这两种类型的雪碧
的,反应到用户交互。不过,我会得到随机崩溃,只有出现以下错误codeS:
12月10日至9日:11:13.532:A / libc的(8015):在0xdeadbaad致命信号11(SIGSEGV)(code = 1)
12月10日至9日:11:13.572:V / AndEngine(8015):org.andengine.input.touch.TouchEvent $ TouchEventPool<&的TouchEvent GT;被耗尽时,而不是2项尚未回收。分配1以上。
12月10日至9日:11:13.572:V / AndEngine(8015):org.andengine.util.adt.pool.PoolUpdateHandler $ 1 LT; TouchEventRunnablePoolItem>被耗尽时,而不是2项尚未回收。分配1以上。
12月10日至9日:11:13.602:V / AndEngine(8015):org.andengine.input.touch.TouchEvent $ TouchEventPool<&的TouchEvent GT;被耗尽时,不是3项尚未回收。分配1以上。
12月10日至9日:11:13.602:V / AndEngine(8015):org.andengine.util.adt.pool.PoolUpdateHandler $ 1 LT; TouchEventRunnablePoolItem>被耗尽时,不是3项尚未回收。分配1以上。
12月10日至9日:11:13.622:V / AndEngine(8015):org.andengine.input.touch.TouchEvent $ TouchEventPool<&的TouchEvent GT;被耗尽时,不是4项尚未回收。分配1以上。
12月10日至9日:11:13.622:V / AndEngine(8015):org.andengine.util.adt.pool.PoolUpdateHandler $ 1 LT; TouchEventRunnablePoolItem>被耗尽时,不是4项尚未回收。分配1以上。
12月10日至9日:11:16.195:V / AndEngine(8015):org.andengine.input.touch.TouchEvent $ TouchEventPool<&的TouchEvent GT;被耗尽时,而不是5项尚未回收。分配1以上。
12月10日至9日:11:16.195:V / AndEngine(8015):org.andengine.util.adt.pool.PoolUpdateHandler $ 1 LT; TouchEventRunnablePoolItem>被耗尽时,而不是5项尚未回收。分配1以上。
12月10日至9日:11:16.275:V / AndEngine(8015):org.andengine.input.touch.TouchEvent $ TouchEventPool<&的TouchEvent GT;被耗尽时,不是6项尚未回收。分配1以上。
12月10日至9日:11:16.275:V / AndEngine(8015):org.andengine.util.adt.pool.PoolUpdateHandler $ 1 LT; TouchEventRunnablePoolItem>被耗尽时,不是6项尚未回收。分配1以上。
当我继续移动我的手指在屏幕上时,的TouchEvent
池警告继续弹出,但游戏本身挂起。老实说,我不知道是什么原因造成这个!我已经做了很多的四处张望,甚至不能找出一个单一的动作崩溃。
我的创建方法/删除我的精灵如下:
TypeASprite
- 内创建一个
TimerHandler
- 在
ContactListener
删除生成一个runOnUpdateThread()
的Runnable
TypeBSprite
- 中创建一个重写
onSceneTouchEvent()
,因为活动的延伸IOnSceneTouchListener
。 - 在
ContactListener
删除生成一个runOnUpdateThread()
的Runnable
每次雪碧
创建,它添加到其各自的的ArrayList
。当它需要被删除,它免去了的ArrayList
通过 ContactListener
。
任何帮助/意见将是非常美联社preciated!谢谢!
编辑:经过一些试验和错误,我在 pretty 的确定问题出在TypeBSprite
编辑:我实现了这样的我TypeBSprite创建:
mEngine.runOnUpdateThread(新的Runnable(){
@覆盖
公共无效的run(){
AnimatedSprite精灵=新AnimatedSprite(SX,SY,mSpriteRegion,getVertexBufferObjectManager()); sprite.setRotation(sRotation);
mScene.attachChild(精灵); 美体= PhysicsFactory.createBoxBody(mPhysicsWorld,雪碧,BodyType.StaticBody,MY_FIXTURE);
sprite.setUserData(spiteB);
body.setUserData(精灵);
mPhysicsWorld.registerPhysicsConnector(新PhysicsConnector(雪碧,身体,真实,真实));
}
});
想通了!问题在于注册一个 runOnUpdateThread
的Runnable
键,它的实际执行之间的时间间隔。问题是, ContactListener
正在调用多次为同一碰撞,从而 runOnUpdateThread
被用来删除该机构正在对同一对象多次调用。
要解决这个问题,我做了 ContactListener
设置的UserData code>雪碧到已删除。当
ContactListener
是同一个对象上再次呼吁,在如果(...)
比较说明雪碧
的的UserData code>会忽略它,因为它应该是道路已经删除的。
希望这可以帮助别人的未来!
I'm developing a game with android using andengine. Basically, I'm using 2 ArrayList
to store my 2 types of Sprites. I'm adding and removing both types of Sprite
at runtime, in reaction to user interaction. However, I'll get random crashes with only the following error codes:
10-09 12:11:13.532: A/libc(8015): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1)
10-09 12:11:13.572: V/AndEngine(8015): org.andengine.input.touch.TouchEvent$TouchEventPool<TouchEvent> was exhausted, with 2 item not yet recycled. Allocated 1 more.
10-09 12:11:13.572: V/AndEngine(8015): org.andengine.util.adt.pool.PoolUpdateHandler$1<TouchEventRunnablePoolItem> was exhausted, with 2 item not yet recycled. Allocated 1 more.
10-09 12:11:13.602: V/AndEngine(8015): org.andengine.input.touch.TouchEvent$TouchEventPool<TouchEvent> was exhausted, with 3 item not yet recycled. Allocated 1 more.
10-09 12:11:13.602: V/AndEngine(8015): org.andengine.util.adt.pool.PoolUpdateHandler$1<TouchEventRunnablePoolItem> was exhausted, with 3 item not yet recycled. Allocated 1 more.
10-09 12:11:13.622: V/AndEngine(8015): org.andengine.input.touch.TouchEvent$TouchEventPool<TouchEvent> was exhausted, with 4 item not yet recycled. Allocated 1 more.
10-09 12:11:13.622: V/AndEngine(8015): org.andengine.util.adt.pool.PoolUpdateHandler$1<TouchEventRunnablePoolItem> was exhausted, with 4 item not yet recycled. Allocated 1 more.
10-09 12:11:16.195: V/AndEngine(8015): org.andengine.input.touch.TouchEvent$TouchEventPool<TouchEvent> was exhausted, with 5 item not yet recycled. Allocated 1 more.
10-09 12:11:16.195: V/AndEngine(8015): org.andengine.util.adt.pool.PoolUpdateHandler$1<TouchEventRunnablePoolItem> was exhausted, with 5 item not yet recycled. Allocated 1 more.
10-09 12:11:16.275: V/AndEngine(8015): org.andengine.input.touch.TouchEvent$TouchEventPool<TouchEvent> was exhausted, with 6 item not yet recycled. Allocated 1 more.
10-09 12:11:16.275: V/AndEngine(8015): org.andengine.util.adt.pool.PoolUpdateHandler$1<TouchEventRunnablePoolItem> was exhausted, with 6 item not yet recycled. Allocated 1 more.
As I continue to move my finger on the screen, the TouchEvent
pool warnings continue popping up, but the game itself is hung. I honestly have no idea what is causing this! I've done a lot of looking around, and can't even pinpoint the crash on a single action.
My method of creating/removing my Sprites is as follows:
TypeASprite:
- create inside a
TimerHandler
- remove inside
ContactListener
spawning arunOnUpdateThread()
Runnable
TypeBSprite:
- create inside a overriden
onSceneTouchEvent()
, since the Activity extends anIOnSceneTouchListener
. - remove inside
ContactListener
spawning arunOnUpdateThread()
Runnable
Each time a Sprite
is created, it's added to its respective ArrayList
. When it needs to be removed, it's removed from the ArrayList
through the ContactListener
.
Any help/ideas would be really appreciated! Thanks!
EDIT: Through some trial and error, I'm pretty sure the issue is with the TypeBSprite
EDIT: I've implemented my TypeBSprite creation like this:
mEngine.runOnUpdateThread(new Runnable() {
@Override
public void run() {
AnimatedSprite sprite = new AnimatedSprite(sX, sY, mSpriteRegion, getVertexBufferObjectManager());
sprite.setRotation(sRotation);
mScene.attachChild(sprite);
Body body = PhysicsFactory.createBoxBody(mPhysicsWorld, sprite, BodyType.StaticBody, MY_FIXTURE);
sprite.setUserData("spiteB");
body.setUserData(sprite);
mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(sprite, body, true, true));
}
});
Figured it out! The problem lies in the time gap between registering an runOnUpdateThread
Runnable
and the actual execution of it. The problem was that the ContactListener
was being called multiple times for the same collision, and thus the runOnUpdateThread
being used to delete the bodies was being called multiple times on the same object.
To fix it, I made the ContactListener
set the UserData
of the Sprite to "deleted". When the ContactListener
was called again on the same object, the "if (...)
statements comparing Sprite
's UserData
would ignore it, since it should be on the road to deletion already.
Hope this helps someone in the future!
这篇关于AndEngine:获取SIGSEGV和TouchEventPool活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!