Jump to content
  • Advertisement
Sign in to follow this  
Fuzztrek

STL: List strangeness

This topic is 4996 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

I'm writing a simple Direct3D enumerator that goes through all of the supported adapters, display modes, etc and places them in different lists. Unfortunately, after I've populated them I seem to run into trouble. I guess it would just be easier to show the code:
// Adapter info iterator
std::list<SD3DAdapterInfo>::iterator Adapter;

// t = 1
int t = m_Enumeration.GetAdapterInfo().size();

// This works fine.. test is equal to the info I populated the list with before
SD3DAdapterInfo test = m_Enumeration.GetAdapterInfo().front();

//  This works fine.. test is still the same value
test = (*m_Enumeration.GetAdapterInfo().begin());

// Set iterator Adapter to the beginning
Adapter = m_Enumeration.GetAdapterInfo().begin();

// access the element from the iterator
//causes unhandled exception
// access violation reading location 0xfeeefef2.
test = (*Adapter);
As far as I can tell, accessing the actual element through the iterator is no different than *m_Enumeration.GetAdapterInfo().begin();, yet it causes an access violation. Anyone know what's going on?

Share this post


Link to post
Share on other sites
Advertisement
Does GetAdapterInfo() return a std::list<SD3DAdapterInfo> by reference or by value? It should return it by reference, or else the returned object will be destroyed at the end of the line, and you'll have an iterator pointing to 'deleted' memory.

Good:
std::list<SD3DAdapterInfo>& GetAdapterInfo()
{
...
}

'Bad':
std::list<SD3DAdapterInfo> GetAdapterInfo()
{
...
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Use debugger and step trought he code.

Share this post


Link to post
Share on other sites
Quote:
Original post by dalleboy
Does GetAdapterInfo() return a std::list<SD3DAdapterInfo> by reference or by value? It should return it by reference, or else the returned object will be destroyed at the end of the line, and you'll have an iterator pointing to 'deleted' memory.

Good:
std::list<SD3DAdapterInfo>& GetAdapterInfo()
{
...
}

'Bad':
std::list<SD3DAdapterInfo> GetAdapterInfo()
{
...
}
Aha! Thanks so much :D

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!