誰能告訴我這是爲什麼返回錯誤刪除身體的Box2D
'AL lib目錄下:(EE)alc_cleanup:1臺設備不封閉'
// mouseJoint碰撞回調
private QueryCallback queryCallback = new QueryCallback() {
@Override
public boolean reportFixture(Fixture fixture) {
if(fixture.getBody() == chest){
//add to remove list
bodiesToRemove.add(chest);
}
if (fixture.testPoint(tmp.x, tmp.y)){
reportFixture = fixture.getBody();
}
if (!fixture.testPoint(tmp.x, tmp.y))
return false;
//assigning bodyB to fixture
jointDef.bodyB = fixture.getBody();
jointDef.target.set(fixture.getBody().getWorldCenter());
//jointDef.target.set(tmp.x, tmp.y);// initial target point coincide with body anchor
joint = (MouseJoint) world.createJoint(jointDef);// creating the join the physics world
return false;
}
};
//主渲染循環
public void render(float delta) {
// TODO Auto-generated method stub
//code clears the screen with the given RGB colour (black)
Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.setCamera(camera);
stage.act(Gdx.graphics.getDeltaTime());
camera.position.x= chest.getPosition().x;
camera.update();
stage.draw();
world.step(1/60f, 8, 3);
renderer.render(world, camera.combined);
/////////////////////////////////////////////////////////////////
//這是我嘗試刪除主體時導致錯誤的代碼
if(bodiesToRemove != null){
for(int i = 0; i <bodiesToRemove.size; i++){
Body b = bodiesToRemove.get(i);
if(b != null){
world.destroyBody(b);
b.setUserData(null);
b = null;
}
bodiesToRemove.clear();
}
}
////////////////////////////////////////////////////////////
}
/////////////////////// ///////////// 我改變了它,它的工作(粘貼在下面),如果有人會喜歡解釋正確的方式來做到這一點,或者如果這是有用的正確方法。 我只是增加了一個布爾值,以防止它破壞關節
// ////////////////// TOUCH EVENT ///////////////////////////////
//Called when a finger was lifted or a mouse button was released.
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
//If no mouseJoint do nothing
System.out.println("touch" + (screenY*0.01f));
System.out.println("touch" + (screenX*0.01f));
if (joint == null)
return false;
//When user is not touching Screen destroy the
//mouseJoint/set to null
if(ran == false){
world.destroyJoint(joint);
joint = null;}
ran = false;
return true;
}
////////////////////////////////
////////////////////////////// ///
if(!world.isLocked() && world.getBodyCount() > 0){
for(int i = 0; i <bodiesToRemove.size; i++){
Body b = bodiesToRemove.get(i);
if(b == null){
bodiesToRemove.removeIndex(i);
continue;
}
world.destroyBody(b);
ran = true;
bodiesToRemove.removeIndex(i);
}
}else{
bodiesToRemove.clear();
}
////////////////////////////////////////////////////////////
我認爲的第一件事就是想要刪除正在使用的Body,但是看到AL,放棄它,我的問題是,box2d在與AL相關時會拋出錯誤?雖然邏輯會讓它發送,如果應用程序崩潰,我想問你是否只拋出這個錯誤「AL lib ....」或由其他人陪同,要知道,從來沒有我持續 – 2015-03-02 12:00:42
Box2D不會拋出該錯誤,實際應用確實如此。它由於崩潰而被拋出,大多數Box2D崩潰導致應用程序掛起,然後CTD,因此AL庫沒有時間清理。所以它打印這個錯誤。 – Gibbo 2015-03-02 12:05:33
感謝您的迴應沒有發生在我身上,看到AL lib放棄他所相信的,原則上哈哈,感謝您的澄清,我認爲你的回答是正確的我刪除我的 – 2015-03-02 12:09:01