C ++ PugiXML向量迭代器不兼容的错误

时间:2013-05-27 02:37:51

标签: c++ visual-studio-2010 box2d sfml pugixml

我有一个应用程序,我使用PugiXML将XML代码解析为带有纹理的sprite。但是,我遇到了使这一for循环工作的问题,因为编译器在循环期间始终返回Expression: vector iterators incompatible运行时错误,就在启动initCollisionObject时。任何帮助将不胜感激!

for循环:

for (xml_node collisions = doc.child("level").child("collisions").child("object"); collisions; collisions = collisions.next_sibling("object"))
{
    xml_attribute textureAttribute = collisions.attribute("spritesheet");
    xml_attribute xPosAttribute = collisions.attribute("x");
    xml_attribute yPosAttribute = collisions.attribute("y");
    xml_attribute rotationAttribute = collisions.attribute("rotation");

    std::string texture = textureAttribute.as_string();
    int xPos = xPosAttribute.as_int();
    int yPos = yPosAttribute.as_int();
    int rotation = rotationAttribute.as_int();

    collisionArray.push_back(collisionObject);
    collisionArray[currentCollisionObjectIndex].initCollisionObject(texture, _world, xPos, yPos, rotation);

    currentCollisionObjectIndex++;
}

initCollisionObject功能:

void CollisionObject::initCollisionObject(std::string fileName, b2World &_world, float objectX, float objectY, float objectRotation)
{
    collisionObjectSpriteImage.loadFromFile(fileName);
    //spriteImage.createMaskFromColor(sf::Color::White);
    collisionObjectSpriteTexture.loadFromImage(collisionObjectSpriteImage);
    collisionObjectSprite.setTexture(collisionObjectSpriteTexture);
    width = collisionObjectSprite.getGlobalBounds().width;
    height = collisionObjectSprite.getGlobalBounds().height;
    x = objectX;
    y = objectY;
    rotation = objectRotation;
    collisionObjectSprite.setOrigin(collisionObjectSprite.getGlobalBounds().width / 2, collisionObjectSprite.getGlobalBounds().height / 2);
    collisionObjectSprite.setPosition(x, y);
    collisionObjectSprite.setRotation(rotation);

    createStaticCollision(_world, x, y, width, height, rotation);

    return;
}

1 个答案:

答案 0 :(得分:0)

这听起来很荒谬,但重启计算机实际上解决了这个问题......