title: Crash when calling clear on an Empty Map
body: <p>I'm getting a strange crash when I try to interact with a map in this particular class. When I try to call clear() or even begin() on the map it crashes. I haven't added anything to map, at this point nothing has touched it at all.</p>
  
  <p>Code in question:</p>
  
  <pre><code>spriteMap_.clear();
  if (!spriteMap_.empty())
  {
      SpriteMap::const_iterator end = spriteMap_.end();
      for (SpriteMap::const_iterator it = spriteMap_.begin(); it != end; ++it)
      {
          it-&gt;second-&gt;draw(screen);
      }
  }
  </code></pre>
  
  <p>Even stranger is that this is not unique to the map but to any maps in this particular class. I have another map, that is also not being touched until here (I tested it with a clear call in this function).</p>
  
  <p>When I use intelli-sense on the maps both show themselves with tons of values already in them and the empty() call returns false. Similarily, size() returns a non-zero result.</p>
  
  <p>Info:
  I'm compiling in Visual Studios 2010 and linking against SDL.</p>
  
  <p>Any help is appreciate.</p>
  
  <p><strong>Edit (more info):</strong></p>
  
  <p>My header has this line:</p>
  
  <p><code>
      private:
      std::map spriteMap_;
  </code></p>
  
  <p>And the only code that is hit is the function I showed you. I have other code but the break point on the function is never hit (I don't call that function).</p>
  
  <p>But here it is:</p>
  
  <pre><code>Sprite* SpriteManager::createSprite(std::string fileName)
  {
     ...
  
     Sprite* newSprite = &amp;Sprite(nextSpriteId_, this, image);
     nextSpriteId_++;
     spriteMap_[newSprite-&gt;id_] = newSprite;
     return newSprite;
  }
  </code></pre>
  
  <h2><strong>Fixed:</strong></h2>
  
  <p><strong>Moral of the story is don't ever do something like this:</strong></p>
  
  <pre><code>ObjPtr* objPtr = &amp;Obj();
  </code></pre>