我正在使用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
. 当它需要被移除时,它会ArrayList
从ContactListener
.
任何帮助/想法将不胜感激!谢谢!
编辑:通过一些试验和错误,我很确定问题出在 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));
}
});