我正在使用andengine开发一款带有android的游戏。基本上,我使用2 ArrayList
来存储我的两种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
池警告会继续弹出,但游戏本身已挂起。老实说,我不知道是什么导致了这个!我做了很多环顾四周,甚至无法确定单个动作的崩溃。
我创建/删除我的Sprite的方法如下:
TypeASprite :
TimerHandler
ContactListener
runOnUpdateThread()
Runnable
内部
TypeBSprite :
onSceneTouchEvent()
内创建,因为活动扩展了IOnSceneTouchListener
。ContactListener
runOnUpdateThread()
Runnable
内部
每次创建Sprite
时,都会将其添加到各自的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));
}
});
答案 0 :(得分:4)
想出来!问题在于注册runOnUpdateThread
Runnable
与实际执行之间的时间差距。问题是同一次碰撞多次调用ContactListener
,因此在同一对象上多次调用用于删除实体的runOnUpdateThread
。
要解决此问题,我将ContactListener
设置为Sprite的UserData
为“已删除”。当在同一个对象上再次调用ContactListener
时,比较if (...)
的{{1}}的“Sprite
语句会忽略它,因为它应该已经被删除了。
希望这可以帮助将来的某个人!
答案 1 :(得分:1)
错误的主要原因致命信号11(SIGSEGV)位于0x28ac9648(代码= 1) 是由于堆栈已满,您需要在运行时清除堆栈或回收
在log cat中查看您正在分配项目但不回收
它还给出了6件尚未回收的错误
因此,如果你继续回收旧物品,你将找到游戏 工作正常,没有任何错误