As you can see, for any number of models greater than 2, the number of "what" outputs is 2. I've tried it for 2-5 models. All of them produce two "what" strings, yet output the correct size of the std::map.

Assuming the above code prints the results quoted, it is pretty clear that the ModelMap data structure got corrupted in some way. The corruption almost certainly took place before this function was called. How the map got corrupted exactly is impossible to tell based on the quoted code and data. The two most likely candidates are

The keys of some of values got changed (assuming the data structure is, indeed, a map).

The internal pointers got overwritten at some point.

I would probably guess the latter although this normally results in a crash rather than some partial output. A potential reason could be that the object being looked at happens to be destroyed object returned by reference from a function. However, this is all pretty much guesswork: To locate the error, you'd need to post more code, removing a lot of the irrelevant code as well (i.e., posting hundreds lines of code won't give you an answer where the problem is exactly, nor will the above code, however).