2

我正在使用andengine 与android 开发游戏。基本上,我使用 2ArrayList来存储我的 2 种 Sprite。我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池警告继续弹出,但游戏本身已挂起。老实说,我不知道是什么原因造成的!我环顾四周,甚至无法确定单个动作的崩溃。

我创建/删除我的精灵的方法如下:

类型 ASprite

  • 在里面创建TimerHandler
  • 删除里面ContactListener产卵runOnUpdateThread() Runnable

类型 BSprite

  • 在覆盖内创建onSceneTouchEvent(),因为 Activity 扩展了IOnSceneTouchListener.
  • 删除里面ContactListener产卵runOnUpdateThread() Runnable

每次Sprite创建 a 时,它都会添加到其各自的ArrayList. 当它需要被移除时,它会ArrayListContactListener.

任何帮助/想法将不胜感激!谢谢!

编辑:通过一些试验和错误,我确定问题出在 TypeBSprite

编辑:我已经像这样实现了我的 TypeBSprite 创建:

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)); 
    }
});
4

2 回答 2

4

弄清楚了!runOnUpdateThread Runnable问题在于注册和实际执行之间的时间差距。问题是ContactListener对于同一个碰撞被多次调用,因此runOnUpdateThread用于删除身体的被调用在同一个对象上被多次调用。

为了解决这个问题,我将 Sprite 的ContactListener设置设置UserData为“已删除”。当在ContactListener同一个对象上再次调用时,比较的 "语句if (...)会忽略它,因为它应该已经在删除的路上了。SpriteUserData

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

于 2012-10-15T04:16:50.287 回答
1

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

look in log cat you are allocating items but not recycling

its also giving error with 6 item not yet recycled

thus if u keep on recycling older items you wll find game working fine without any error

于 2013-05-24T05:52:05.883 回答