我正在开发游戏和引擎。它崩溃了非常烦人的错误信息。变换体改变位置时发生崩溃。我正在使用body.setTransform
方法来改变位置。我的代码正在关注。
public Scene onCreateScene() {
this.mScene = new Scene();
this.mScene.setBackground(new Background(0, 0, 0));
this.mScene.setOnSceneTouchListener(this);
this.mScene.setOnAreaTouchListener(this);
this.mPhysicsWorld = new PhysicsWorld(new Vector2(0, 10), false);
// Some Code.
faceBox = new Sprite(bx, CAMERA_HEIGHT-mPlayerTextureRegion.getHeight()-25, this.mPlayerTextureRegion, this.getVertexBufferObjectManager());
body = PhysicsFactory.createCircleBody(mPhysicsWorld, faceBox.getRotationCenterX(), faceBox.getRotationCenterY(), faceBox.getWidthScaled() * 0.6f, BodyType.DynamicBody, FIXTURE_DEF);//(this.mPhysicsWorld, faceBox, BodyType.DynamicBody, FIXTURE_DEF);
body.setFixedRotation(true);
body.setUserData("player");
this.mScene.attachChild(faceBox);
this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(faceBox, body, true, true));
// Some Code.
this.mEngine.registerUpdateHandler(new FPSLogger(){
@Override public void onUpdate(float pSecondsElapsed) {
try{
if(ball.getPosition().x<=n.getPosition().x&&ball.getPosition().y<body.getPosition().y-1.3f&&difficulty){
body.setTransform(ball.getPosition().x-0.6f<(l.getPosition().x+2*(l.getPosition().x-l.getWorldCenter().x)+0.83f)?(l.getPosition().x+2*(l.getPosition().x-l.getWorldCenter().x)+0.83f):ball.getPosition().x-0.6f,body.getPosition().y,body.getAngle());
}
}catch(Exception e){
e.printStackTrace();
}
// Some Code.
});
}
return this.mScene;
}
来自logcat的错误日志是。
03-03 13:02:16.374: A/libc(5892): /Users/ngramlich/Workspace/gdk/graphic_engines/AndEngine/AndEnginePhysicsBox2DExtension/jni/Box2D/Dynamics/b2Body.cpp:395: void b2Body::SetTransform(const b2Vec2&, float32): assertion "m_world->IsLocked() == false" failed
03-03 13:02:16.375: A/libc(5892): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 5936 (Thread-474)
答案 0 :(得分:0)
当PhysicsWorld
被锁定时崩溃。您应该使用isLocked
方法检查是否已锁定。你的代码应该使用它。
if(!mPhysicsWorld.isLocked())
body.setTransform(ball.getPosition().x-0.6f<(l.getPosition().x+2*(l.getPosition().x-l.getWorldCenter().x)+0.83f)?(l.getPosition().x+2*(l.getPosition().x-l.getWorldCenter().x)+0.83f):ball.getPosition().x-0.6f,body.getPosition().y,body.getAngle());