2013-05-27 60 views
0

我有一個應用程序,我使用PugiXML將XML代碼解析爲具有紋理的精靈。但是,我遇到了一個for循環工作的問題,因爲編譯器在循環過程中不斷返回Expression: vector iterators incompatible運行時錯誤,正當initCollisionObject啓動時。任何幫助將不勝感激!C++ PugiXML向量迭代器不兼容錯誤

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; 
} 

回答

0

這是要聽起來很可笑,但在重新啓動計算機實際上解決了這個問題...