title: crashing when erasing in a map (C++)
body: <p>Here is a part of code that is crashed always. I can't understand the reason of this crash. All I do is set some pointers in a loop. If I comment this cycle all will be OK. It's strange.. The code in the bottom is where the crash happend. I can't get what destructor is called and why my program is crahsing.</p>
  
  <pre><code>    typedef std::set&lt;IDrawable**&gt; TDrawableList;
          typedef std::map&lt;std::string, TDrawableList&gt; THashLoad;
  //  ...
      THashLoad::iterator itLoad =  gpMapRenderer-&gt;m_unloadedCells.find(file.substr(6, file.length()));
          if (itLoad != gpMapRenderer-&gt;m_unloadedCells.end())
          {
                  TDrawableList::iterator itCells = itLoad-&gt;second.begin();
                  TDrawableList::iterator itCellsEnd = itLoad-&gt;second.end();
                  for (; itCells != itCellsEnd; ++itCells)
                  {
                          **itCells = (IDrawable*)itHashPics-&gt;second.pImg;
                  }
  
                  gpMapRenderer-&gt;m_unloadedCells.erase(itLoad);  // &lt; --- CRASH
          }
      // ... 
      // _construct.h
      // ...
  template &lt;class _Tp&gt;
  inline void _Destroy(_Tp* __pointer) {
  # if _MSC_VER &gt;= 1010
    __pointer;
  # endif    // _MSC_VER &gt;= 1000
  # ifdef _STLP_TRIVIAL_DESTRUCTOR_BUG
    typedef typename __type_traits&lt;_Tp&gt;::has_trivial_destructor _Trivial_destructor;
    __destroy_aux(__pointer, _Trivial_destructor());
  # else
  #  if ( defined (__BORLANDC__) &amp;&amp; ( __BORLANDC__ &lt; 0x500 ) )
      __pointer-&gt;_Tp::~_Tp();
  #  else
      __pointer-&gt;~_Tp(); // &lt; ---- CRASH
  #  endif
  # endif
  # ifdef _STLP_DEBUG_UNINITIALIZED
          memset((char*)__pointer, _STLP_SHRED_BYTE, sizeof(_Tp));
  # endif
  }
  </code></pre>
  
  <p>P.S. My program is single-threaded.</p>
  
  <p>Thank you.</p>
  
  <p>Update:</p>
  
  <pre><code>class IDrawable
  {
  public:
      virtual ~IDrawable() {};
  
      virtual void Draw(const CIwSVec2&amp; pos) = 0;
      virtual void Draw(const CIwSVec2&amp; pos, const CIwSVec2&amp; size) { IwAssert(IDRAWABLE, "Not Implemented");};
  };
  </code></pre>
  
  <p>So here is how I add to m_unloadedCells:</p>
  
  <pre><code>void MapRenderer::AddCellToUnloadedList(const std::string&amp; filename, IDrawable** pElement)
  {
      THashLoad::iterator itLoad = m_unloadedCells.find(filename);
      if (itLoad != m_unloadedCells.end())
          itLoad-&gt;second.insert(pElement);
      else
      {
          std::set&lt;IDrawable**&gt; _set;
          _set.insert(pElement);
          m_unloadedCells.insert(make_pair(filename, _set));
      }
  }
  </code></pre>
  
  <p>and somewhere in the code:</p>
  
  <pre><code>AddCellToUnloadedList(filenameToLoad, &amp;itHashCells-&gt;second[index].drawingElement[i].pDrawable)
  </code></pre>
  
  <p>itHashcells:</p>
  
  <pre><code>typedef std::map&lt;int, std::vector&lt;Cell2&gt; &gt; THashCells;
  THashCells itHashCells;
  </code></pre>
  
  <p>Cell2:</p>
  
  <pre><code>enum eDrawableType
  {
      DTYPE_Sprite = 0,
      DTYPE_Animation
  };
  
  struct DrawingElement
  {
      eDrawableType type;
      IDrawable* pDrawable;
  };
  
  struct Cell2
  {
      Cell2()
      {
          drawingElement.reserve(10);
      }
  
      int location;
      int x, y;
  
      std::vector&lt;DrawingElement&gt; drawingElement;
  
      MinimapTileInfo minimap_tile_info[10];
  };
  </code></pre>