tags:

views:

45

answers:

2

Definition:

std::map<unsigned, CItem*> m_map;

void RegisterEvent(unsigned eventID) {
  std::map<unsigned, CItem*>::iterator it = m_map.find(eventID); <<< crashes
  if (it == m_map.end()) {
    m_map[eventID] = new CItem();
  }
  else {
    ...
  }
}

The marked row crashes in std::less on second call, the first call works. When watching callstack, the __x argument seems WAY off (as the # of events is < 40, but __x is like 2354918952 (or something else big))...

Ideas?

TIA /R

+2  A: 

It looks like something has corrupted the memory of your program. This is highly unlikely to be std::map - this just happens to be where the problem manifests itself. You need to look at your own code for the source of the problem.

And not to do with your problem, but GCC 3.4 is pretty ancient - the current release is 4.4.2. You might want to upgrade.

anon
Thanks, I subsequently tried the exact same impl, but with an unordered_map (actually I was using gcc 4.3 as I discovered later on), and that worked. Go figure. Anyway, I reverted to using a simple array the size of events in the system, that way also the selection of an item is O(1).
Robert
A: 

I don't see anything wrong with the code you posted. Since the first call to the function works, I would think that the problem is in the code you didn't post (I would first look at the else block or after it). Something is making the map invalid.

Max Lybbert