Skip to main content
gamedev.net
🔒 Locked

std::map.clear() on empty map producers size() = -1

Started by steve coward Aug 8, 2007 at 3:19 PM 5 replies 2.2k views
Original Post
steve coward
steve coward
I assume it is legal to call clear() on an empty std::map. However, in the code below the first ASSERT does not trigger but the second ASSERT does trigger.

ASSERT(pPlayerInfo->m_pDrawSelectedUnitMap->empty());
pPlayerInfo->m_pDrawSelectedUnitMap->clear();
ASSERT(pPlayerInfo->m_pDrawSelectedUnitMap->empty());

In the debugger I see that the size of m_pDrawSelectedUnitMap is -1 (0xffffffff) after the clear. What could I have done previously to the state of m_pDrawSelectedUnitMap to screw this up? I would think that 'empty' means empty and any other map state would be irrelevant or consistent. thanks
Antheus
Antheus
Which compiler, OS, etc....

Also, did you try that with stand-alone example to ensure it's not a memory overrun corrupting the memory under the map?
steve coward
steve coward
VC 6.0

At the start of my code, the listed code sequence works as
expected; later on it breaks.

It could be a memory corruption problem. Is it possible
that it might also be an odd sequence of operations upon the map?

I am in the process of changing many containers from MFC - CMap to std::map, etc. In this process I surely have made numerous typos that I am now debugging.


thanks
Promit
Promit
Step 1: Stop using VC6.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
steve coward
steve coward

lol.

Actually the removal of MFC is my first step in moving to
2005 Express Edition.
steve coward
steve coward
When I iterate through the map from begin() to end() after the first ASSERT
(which reports that the map is empty) the iteration runs through one element.

When I iterate through the map from begin() to end() after the clear()
the iteration runs through zero elements.

Then the second ASSERT triggers.
steve coward
steve coward
I just found the problem.

I was producing an iterator using find() on a different map of the same type, then using the iterator as an argument to an erase( on the map in question.

Thanks all.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.