0

I'm working on a 3D game and i'm on walking at the moment but when I walk one step I then get a runtime error

'Expression: vector iterators incompatible'

Here is where walking is first called:

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

What I have also found by using breakpoints is that the bottom forloop seems to be where the issue is.

When I add a break point on the following

tempPathWaypoints[i].x += firstStepX;

I get the runtime error but anywhere before that I do not.

Here are the rest of my walking functions. (Put it in pastebin too long for this thread)

http://pastebin.com/ZGiuL2Wf

I am pretty sure that the error is based in the addToWalkingQueue but I am not sure

Cœur
  • 37,241
  • 25
  • 195
  • 267
James Young
  • 313
  • 3
  • 10
  • 19
  • I think you need to add more information about the functions and types you are using here. – Elazar Sep 17 '13 at 21:55
  • It *sounds* like you have iterator-debugging enabled (thankfully) and the end-iterator in `tempPathWaypoints` is being encountered within your implementations `operator []`, then throwing an exception when it attempts to use the dereference operator to acquire a non-const reference required for the statement. A stack dump of the actual error location would likely expose the real culprit. – WhozCraig Sep 17 '13 at 22:09
  • If you post a [minimal complete example](http://sscce.org), you'll get the answer within minutes. – Beta Sep 17 '13 at 22:39
  • 2
    Possible duplicate of [Vector Iterators Incompatible](https://stackoverflow.com/questions/8421623/vector-iterators-incompatible) – Cœur Jan 06 '18 at 06:47

0 Answers0