我正在用andengine开发一个android游戏。基本上,我用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.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.

当我继续在屏幕上移动手指时,TouchEvent池警告继续弹出,但游戏本身被挂起。我真的不知道这是什么原因!我做了很多环顾四周的工作,甚至一个动作都找不到坠机的确切位置。
创建/移除精灵的方法如下:
类型写入:
在aTimerHandler中创建
移除内部生成aContactListenerrunOnUpdateThread()
B类型写入:
在重写的Runnable中创建,因为活动扩展了onSceneTouchEvent()
移除内部生成aIOnSceneTouchListenerContactListener
每次创建runOnUpdateThread()时,都会将其添加到各自的Runnable中。当需要移除时,它会通过SpriteArrayList中移除。
任何帮助/想法都将非常感谢!谢谢!
编辑:通过一些尝试和错误,我确信问题出在typebsprint上
编辑:我已经实现了我的typebscript创建,如下所示:
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));
    }
});

最佳答案

明白了!问题在于注册runOnUpdateThreadRunnable与实际执行之间的时间间隔。问题是ContactListener在同一个碰撞中被多次调用,因此用于删除实体的runOnUpdateThread在同一个对象上被多次调用。
为了解决这个问题,我把精灵的ContactListener设置为“deleted”。当对同一个对象再次调用UserData时,比较ContactListenerif (...)语句将忽略它,因为它应该已经在删除的路上了。
希望这对将来的人有帮助!

07-27 22:25