Visual c++ Gdiplus::Image对象和boost::shared\u ptr

Visual c++ Gdiplus::Image对象和boost::shared\u ptr,visual-c++,boost,mfc,gdi+,shared-ptr,Visual C++,Boost,Mfc,Gdi+,Shared Ptr,我的MFC应用程序中有一个简单的图像缓存类,用于跟踪从文件系统加载的图像: typedef boost::shared_ptr<Gdiplus::Image> ImagePtr; typedef std::map<std::string, ImagePtr> ImageMap; typedef boost::shared_ptr ImagePtr; typedef std::map ImageMap; 每当通过文件名请求图像时,都会执行查找,或者如果已加载图像,则会返

我的MFC应用程序中有一个简单的图像缓存类,用于跟踪从文件系统加载的图像:

typedef boost::shared_ptr<Gdiplus::Image> ImagePtr;
typedef std::map<std::string, ImagePtr> ImageMap;
typedef boost::shared_ptr ImagePtr;
typedef std::map ImageMap;
每当通过文件名请求图像时,都会执行查找,或者如果已加载图像,则会返回相应的ImagePtr

当我退出应用程序,共享指针被破坏时,问题就会出现。我在这里得到一个访问冲突,在checked\u delete.hpp中:

// verify that types are complete for increased safety

template<class T> inline void checked_delete(T * x)
{
    // intentionally complex - simplification causes regressions
    typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
    (void) sizeof(type_must_be_complete);
    delete x; // <-------- violation here!!
}
//验证类型是否完整以提高安全性
模板内联无效已选中\u删除(T*x)
{
//有意的复杂化会导致回归
typedef char type必须是完整的[sizeof(T)1:-1];
(无效)尺寸(类型必须完整);

删除x;//这可能是在指针被销毁之前调用
gdiplussutdown
的症状。

Hm,我实际上并没有显式调用它。但您提出了一个有趣的问题,因为我依赖智能指针,并且图像缓存将在我拥有的CWinApp派生类的析构函数上被销毁。是时候试试了事情:)太好了!谢谢你给我指明了正确的方向。我在
existinstance
中调用了
clear()
,而不是让它们破坏,瞧,没有访问冲突。