Vector iterators incompatible in debug mode

I get this error when i try to run this code for an inventory in debug mode in VS. But for some reason it works just fine in release mode.

1
2
3
4
5
6
7
8
9
10
11
void Push_Back_Item(Item *item){
	for(int y = 0; y < InvSizeY; y ++)
		for(int x = 0; x < InvSizeX; x ++){
			auto Iter = ItemList.find(std::make_pair(x,y));
			if(Iter != ItemList.end()){
				
				item->SetDead(); // ERROR
}
}
}

This isnt the full code though but it still gives me the same error.

The only thing "item->SetDead()" does is to set a bool to true.

This is the map i get the iterator from
std::map<std::pair<int,int>,Item*> ItemList;

This have been bugging me for quite some time now.
There are no vector iterators in the code you supplied, therefore either the error message you supplied is not correct, or the code you supplied does more than you say it does. You seem to indicate that line 7 is where the error occurs. There are no iterators on that line, unless they exist within the Item::SetDead method.

Also, why doesn't your Push_Back_Item function push back any items?
Are you sure item points to a valid object?
What if you reduce it further?
1
2
3
void Push_Back_Item(Item *item){
  item->SetDead();
}

You loops/find does not use "item".

On the other hand, when you have found an "Iter", you don't use it ...
Oh sh*t it wasnt that line that made the error. I know where it is stupid me.....
Sorry
Last edited on
Topic archived. No new replies allowed.