I just came across a strange bug or abnormality, which took me half an hour of my time to find, and another to understand... During my program, I insert values in a map with types <int,FooBar*>.
At a certain point, I insert twice the same key, its supposed to be a normal thing, and the second key should be rejected and the first one kept intact.
Quote
Because map containers do not allow for duplicate key values, the insertion operation checks for each element inserted whether another element exists already in the container with the same key value, if so, the element is not inserted and its mapped value is not changed in any way.
It seems to do this. But sometime after, I need to call find() on this precise map to get a value. But the function never returns. It freezes my program do death whatever value I give to find(x)...
Did anyone already had this bug? Did I misunderstand something?
I solved the problem by checking myself if the value already wasn't in the map, but I had hoped that would be automatic.
I use MinGW g++, along with SDL and cPython but I don't think that would influence the stl. I also use windows.h for some parts of my program. Here are the responsable parts of my code:
//the insertion part
Player* newp = new Player;
int pid=m_client->getNewPid();
m_pmap.insert(std::pair<int,Player*>(pid,newp));
//...
//later on
while (m_client->getDeadPlayers(&dead_player_id))//puts the id in this variable, returns false if queue is empty
{
//...
std::map<int,Player*>::iterator it = m_pmap.find(dead_player_id);
//this line freezes
}
Edited by manux, 21 May 2009 - 03:59 AM.


Sign In
Create Account


Back to top









