Jump to content
  • Advertisement
Sign in to follow this  
sipickles

std::map not filling correctly

This topic is 4422 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, ( using MSVC2003 + DX9 ) I am using a std::map to keep track of controls in my GUI, mainly to ensure they are all deleted nicely. This seemed to be working at first, but as I add more controls, there seems to be a problem. In one function call, these commands work g_guiManager->m_buttonList[ wszTitleButtonName ] = m_titleBar; g_guiManager->m_buttonList[ wszCloseButtonName ] = m_close; The buttonList now has size 2; Next time the function is called, the size of buttonList isnt incremented, and yes they do have different names for the Key the second time round. Can anyone suggest possible reason for this or a workaround? a better way of allocating the values perhaps? Thanks S

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Just a shot in the dark. It seems you are using some kind of C-style string (I am guessing from wsz prefix) as a key for the map. This will not work; use for example std::string or std::wstring. The reason is that the map is using a comparison operator ('less than' if I recall), and the strings are decaying into pointers, which probably isn't what you intend. If those are stack allocated, there is a chance that each time the string has the same address, which could be why you don't get a new item in the map.

Again, just a shot in the dark, as without more code I am just guessing. Hope it helps.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!