这是始终崩溃的代码的一部分。我无法理解这次崩溃的原因。我所做的只是在循环中设置一些指针。如果我评论这个循环,一切都会好的。很奇怪..底部的代码是崩溃发生的地方。我不知道调用什么析构函数以及为什么我的程序崩溃了。
typedef std::set<IDrawable**> TDrawableList;
typedef std::map<std::string, TDrawableList> THashLoad;
// ...
THashLoad::iterator itLoad = gpMapRenderer->m_unloadedCells.find(file.substr(6, file.length()));
if (itLoad != gpMapRenderer->m_unloadedCells.end())
{
TDrawableList::iterator itCells = itLoad->second.begin();
TDrawableList::iterator itCellsEnd = itLoad->second.end();
for (; itCells != itCellsEnd; ++itCells)
{
**itCells = (IDrawable*)itHashPics->second.pImg;
}
gpMapRenderer->m_unloadedCells.erase(itLoad); // < --- CRASH
}
// ...
// _construct.h
// ...
template <class _Tp>
inline void _Destroy(_Tp* __pointer) {
# if _MSC_VER >= 1010
__pointer;
# endif // _MSC_VER >= 1000
# ifdef _STLP_TRIVIAL_DESTRUCTOR_BUG
typedef typename __type_traits<_Tp>::has_trivial_destructor _Trivial_destructor;
__destroy_aux(__pointer, _Trivial_destructor());
# else
# if ( defined (__BORLANDC__) && ( __BORLANDC__ < 0x500 ) )
__pointer->_Tp::~_Tp();
# else
__pointer->~_Tp(); // < ---- CRASH
# endif
# endif
# ifdef _STLP_DEBUG_UNINITIALIZED
memset((char*)__pointer, _STLP_SHRED_BYTE, sizeof(_Tp));
# endif
}
PS我的程序是单线程的。
谢谢你。
更新:
class IDrawable
{
public:
virtual ~IDrawable() {};
virtual void Draw(const CIwSVec2& pos) = 0;
virtual void Draw(const CIwSVec2& pos, const CIwSVec2& size) { IwAssert(IDRAWABLE, "Not Implemented");};
};
所以这是我添加到 m_unloadedCells 的方法:
void MapRenderer::AddCellToUnloadedList(const std::string& filename, IDrawable** pElement)
{
THashLoad::iterator itLoad = m_unloadedCells.find(filename);
if (itLoad != m_unloadedCells.end())
itLoad->second.insert(pElement);
else
{
std::set<IDrawable**> _set;
_set.insert(pElement);
m_unloadedCells.insert(make_pair(filename, _set));
}
}
在代码中的某处:
AddCellToUnloadedList(filenameToLoad, &itHashCells->second[index].drawingElement[i].pDrawable)
它哈希单元:
typedef std::map<int, std::vector<Cell2> > THashCells;
THashCells itHashCells;
单元格2:
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<DrawingElement> drawingElement;
MinimapTileInfo minimap_tile_info[10];
};