表达式:矢量迭代器不兼容

时间:2013-09-17 21:48:00

标签: c++ vector

我正在制作一款3D游戏,而我现在正在步行,但当我走一步时,我就会遇到运行时错误

  

'表达式:矢量迭代器不兼容'

这里首先叫走路:

void Packets::handleMoving(Player* p, Stream* s)
{
    printf("handling movement for player: %s\n", p->getUsername());

    int newWalkCmdSteps = (p->packetSize - 5) / 2;

    if(newWalkCmdSteps > WALKING_QUEUE_SIZE)
    {
        printWarning("Warning: walkTo(%d) command contains too many steps (%d).\n", p->packetType, newWalkCmdSteps);
        return;
    }

    PlayerHandler::resetWalkingQueue(p);
    Pos temp;
    vector<Pos> tempPathWaypoints;

    int firstStepX = s->readSignedWordBigEndianA();

    for(int i = 0; i < newWalkCmdSteps; i++) {
        temp.x = s->readSignedByte();
        temp.y = s->readSignedByte();
        tempPathWaypoints.push_back(temp);
    }

    int firstStepY = s->readSignedWordBigEndian(); //absPos

    int isRunning = s->readSignedByteC() == 1; //seems always be 0 so useless..

    PlayerHandler::addToWalkingQueue(p, firstStepX, firstStepY);
    for(int i = 0; i < newWalkCmdSteps; i++) {
        tempPathWaypoints[i].x += firstStepX;
        tempPathWaypoints[i].y += firstStepY;
        PlayerHandler::addToWalkingQueue(p, tempPathWaypoints[i].x, tempPathWaypoints[i].y);
    }
}

我通过使用断点找到的是底部forloop似乎是问题所在。

当我在以下

添加断点时
tempPathWaypoints[i].x += firstStepX;

我得到了运行时错误,但在此之前我没有。

以下是我的其余步行功能。 (把这个帖子放在pastebin中太久了)

http://pastebin.com/ZGiuL2Wf

我很确定错误是基于addToWalkingQueue,但我不确定

0 个答案:

没有答案