Android AndEngine:获取SIGSEGV和TouchEventPool事件

Android AndEngine:获取SIGSEGV和TouchEventPool事件,android,andengine,Android,Andengine,我正在用安卓开发一个游戏。基本上,我使用2ArrayList来存储我的两种精灵。为了响应用户交互,我在运行时添加和删除两种类型的Sprite。但是,我会得到随机崩溃,只有以下错误代码: 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.TouchEven

我正在用安卓开发一个游戏。基本上,我使用2
ArrayList
来存储我的两种精灵。为了响应用户交互,我在运行时添加和删除两种类型的
Sprite
。但是,我会得到随机崩溃,只有以下错误代码:

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.

明白了!问题在于注册
rununupdatethread
Runnable
与实际执行之间的时间间隔。问题在于,同一碰撞多次调用了
ContactListener
,因此,用于删除实体的
runOnUpdateThread
在同一对象上被多次调用

为了修复它,我让
ContactListener
将精灵的
UserData
设置为“deleted”。当对同一对象再次调用
ContactListener
时,比较
Sprite
UserData
的“
if(…)
语句将忽略它,因为它应该已经在删除的路上了


希望这对将来的人有所帮助!

错误的主要原因致命信号11(SIGSEGV)位于0x28ac9648(代码=1) 由于堆栈已满,您需要在运行时清除堆栈或回收

在日志cat中查看您正在分配项目,但不是回收

它也给出了6项尚未回收的错误

所以,如果你继续回收旧物品,你会发现游戏
工作正常,没有任何错误

0xdeadbaad,很有趣。尝试在谷歌上搜索该地址,一些结果似乎很有希望,尤其是感谢,查看了这些结果。我用一些发现进行了更新。你应该在更新线程上可运行的内部添加TypeBScript。Box2D引擎不喜欢从其他地方更改场景。(您使用的是Box2D,对吗?我根据segfault得出结论)是的,我正在使用AndEngine的Box2D扩展。我用更改后的代码进行了更新,但问题仍然存在。是否有其他方法创建可运行的?以不同方式创建可运行的应该不会对问题产生任何影响,这可能不是Java问题。吸引我注意的一件事是fixture,如果您遵守标准nam,它将这是一个常数。我不知道这意味着什么,但试着为每个身体创建一个新的。
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)); 
    }
});