Java 表达式:IsLocked()==false,在引用世界时崩溃?

Java 表达式:IsLocked()==false,在引用世界时崩溃?,java,crash,box2d,Java,Crash,Box2d,错误 AL lib: (EE) alc_cleanup: 1 device not closed Assertion failed! Program: C:\Program Files\Java\jre1.8.0_25\bin\javaw.exe File: /var/lib/jenkins/workspace/libgdx/extensions/gdx-box2d/gdx-box2d/jni/Box2D/Dynamics/b2World.cpp, Line 109 Expression:

错误

AL lib: (EE) alc_cleanup: 1 device not closed
Assertion failed!

Program: C:\Program Files\Java\jre1.8.0_25\bin\javaw.exe
File: /var/lib/jenkins/workspace/libgdx/extensions/gdx-box2d/gdx-box2d/jni/Box2D/Dynamics/b2World.cpp, Line 109

Expression: IsLocked() == false
以下行是错误发生前的最后一行:

Body body = world.createBody(bodyDef);
我不明白这是怎么造成问题的
world
bodyDef
不是
null

我的程序的结构是这样的:我有一个
GameStateRegular
类,它在
init
方法中添加了两个新的
VirusEntity
对象,如下所示:

VirusEntity virus0 = new VirusEntity(world, mother, new Vector2(0, 0));
VirusEntity virus1 = new VirusEntity(world, mother, new Vector2(100, 100));
viruses.add(virus0);
viruses.add(virus1);
这个很好用。我设置了一个
VirusEntity
,当它开始与
MotherCellEntity
联系时,执行以下代码:

private void setContactListener() {
    world.setContactListener(new ContactAdapter() {
        @Override
        public void beginContact(Contact contact) {
            Body bodyA = contact.getFixtureA().getBody();
            Body bodyB = contact.getFixtureB().getBody();

            if (bodyA == mother.getBody()) work(bodyA, bodyB);
            else if (bodyB == mother.getBody()) work(bodyB, bodyA);
        }

        private void work(Body motherCellBody, Body virusBody) {
            VirusEntity virus = null;
            for (VirusEntity v : viruses) {
                if (v.getBody() == virusBody) virus = v;
            }
            virus.remove();
            VirusEntity newVirus = new VirusEntity(world, mother, virus.getSpawnPosition());
            viruses.add(newVirus);
        }
    });
}
我正在引用相同的
World
对象,以及相同的
MotherCellEntity
对象到正在创建的新
VirusEntity
,但我仍然无法判断这里发生了什么

完整
GameStateRegular
类:
完整
VirusEntity
class:


谢谢大家的帮助。我在这个话题上含糊不清,因为我真的不明白发生了什么。我试图做一些背景调查,但没有成功。

我是如何成功的

我所做的是在我的
GameStateRegular
类中的
update
方法中:

@Override
public void update() {
    world.step(1, 1, 1);
    mother.update();
    for (int i = 0; i < viruses.size(); i++) {
        VirusEntity e = viruses.get(i);
        if (e.isRemoved()) {
            viruses.remove(e);
            e.dispose();
            // --v--
            VirusEntity newVirus = new VirusEntity(world, mother, e.getSpawnPosition());
            viruses.add(newVirus);
            // --^--
        } else e.update();
    }
}
IsLocked()==false
如果在物理模拟步骤运行时尝试修改物理世界,则始终会发生。通常,当您尝试在contact/collision回调中从世界中删除实体时,会发生这种情况。
private void setContactListener() {
    world.setContactListener(new ContactAdapter() {

        @Override
        public void preSolve(Contact contact, Manifold manifold) {
            Body bodyA = contact.getFixtureA().getBody();
            Body bodyB = contact.getFixtureB().getBody();

            if (bodyA == mother.getBody()) virusInvolved(bodyA, bodyB);
            else if (bodyB == mother.getBody()) virusInvolved(bodyB, bodyA);
        }

        private void virusInvolved(Body motherCellBody, Body virusBody) {
            VirusEntity virus = null;
            for (VirusEntity v : viruses) {
                if (v.getBody() == virusBody) virus = v;
            }
            if (virus != null) {
                virus.setMovementAllowed(false);
                virus.remove();
            }
        }
    });
}