zerver wrote:I've had some crashes pointing to explosiongenerator.
It seems to store a pointer to a CEGData element in a static std::map, which is illegal to do if the data structure is going to be modified - and it is...
Is it?
Storing iterator to element of std::map is fine even when the map is being modified later:
http://www.sgi.com/tech/stl/Map.html wrote:
Map has the important property that inserting a new element into a map does not invalidate iterators that point to existing elements. Erasing an element from a map also does not invalidate any iterators, except, of course, for iterators that actually point to the element that is being erased.
I'd be surprised if STL implementations store a list of all iterators which point to the map in the map, so they can be updated when the map randomly moves memory around. (as you imply it does - at least, I can't think of any other thing that would cause pointer to be invalidated)
Even then, we could use iterator instead of pointer
cachedCEGs[tag] = cegData;
currentCEG = &cachedCEGs[tag]; // yikes
To me this bug seems pretty severe, I'm surprised the game is running at all
What do you think?
Not surprised at all
Though, having static variable in random function as global cache of some stuff isn't best pattern I can think of...