简体   繁体   English

先知断言失败

[英]Farseer Assertion Failure

We're creating a game for a school project. 我们正在为学校项目创建游戏。 It's a 2D platformer and it is in its very early stages. 这是一个2D平台游戏,尚处于起步阶段。 We use C#/XNA and we're implementing Farseer Physics Engine. 我们使用C#/ XNA,并且正在实现Farseer物理引擎。 I'm currently struggling with the map-class. 我目前在与地图类斗争。 In the class we have a List of DrawableGameObjects, were we store each tile of the map and draw them. 在该类中,我们有一个DrawableGameObjects列表,用于存储地图的每个图块并绘制它们。 But when we try to draw them we get a "Assertion Failed". 但是,当我们尝试绘制它们时,我们会收到“断言失败”的提示。 Examining the problem even further I've come to the conclusion that whenever we try to add more than to static bodies to the world (even without drawing them) we get this failure. 进一步研究这个问题,我得出的结论是,每当我们尝试向世界添加更多静态物体(即使不绘制它们)时,都会遇到这种失败。 Throw message 抛出消息

Game1.cs:line 210 is: Game1.cs:第210行是:

world.Step(0.033333f);

And Program.cs:line 15 is: 而Program.cs:第15行是:

game.Run();

Here is the code for the Map class: 这是Map类的代码:

class Map
{
    private List<DrawableGameObject> ground = new List<DrawableGameObject>();

    public Map(World world, Texture2D texture)
    {
        for (int i = 0; i < 32; i++)
        {
            DrawableGameObject floor = new DrawableGameObject(world, texture, new Vector2(40, 40), 100, "ground");
            floor.Position = new Vector2(i * 40, 500);
            floor.body.BodyType = BodyType.Static;
            ground.Add(floor);
        }

    }

    public void Draw(SpriteBatch spriteBatch){
        foreach (DrawableGameObject dgo in ground)
            dgo.Draw(spriteBatch);

    }

}

Any ideas? 有任何想法吗? I've posted the problem on Farseer's forum , but they haven't been very helpful yet... 我已经在Farseer的论坛上发布了问题,但是他们还没有帮助很大……

This is a bug in Farseer. 这是Farseer中的错误。 (Version 3.3.1) (版本3.3.1)

I opened up the Farseer source code to the method in question ( World.SolveTOI ) and found two calls to Debug.Assert . 我向相关方法( World.SolveTOI )打开了Farseer源代码,并发现了两个对Debug.Assert调用。 And, in fact, in my copy of the code, I've actually already come across this bug and commented one of them out, specifically: 而且,实际上,在我的代码副本中,我实际上已经遇到了该错误,并注释了其中一个,特别是:

Debug.Assert(typeA == BodyType.Dynamic || typeB == BodyType.Dynamic);

Basically it doesn't want to attempt to handle contacts between two bodies that are static. 基本上,它不想尝试处理两个静态的物体之间的接触。

Fortunately the code immediately below actually checks for essentially the same condition, and continue s the loop if that is the case: 幸运的是,下面的代码实际上检查了基本相同的条件,并且在这种情况下continue执行循环:

bool awakeA = bA.Awake && typeA != BodyType.Static;
bool awakeB = bB.Awake && typeB != BodyType.Static;

// Is at least one body awake?
if (awakeA == false && awakeB == false)
{
    continue;
}

So it's quite safe to simply comment out or remove the assertion. 因此,简单地注释掉或删除断言是非常安全的。 (You should, of course, be building Farseer from source - it makes life much easier.) (当然,您应该从源头构建Farseer,这使生活变得更加轻松。)


To reproduce the Farseer bug: Have two static bodies and one dynamic body that is in contact with both, then make the dynamic body static. 重现Farseer错误:让两个静态物体和一个与两者接触的动态物体,然后使动态物体静态。 The assert will trigger. 断言将触发。

The assert is in the contact handling loop. 断言在联系人处理循环中。 Normally a pair of static bodies wouldn't create contacts. 通常,一对静态实体不会创建接触。 But if a body starts out as dynamic, contacts can be created - they don't get removed when the body is made static. 但是,如果某个实体开始时是动态的,则可以创建联系人-将其设为静态时不会删除它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM