Gdiplus::Image 对象和 boost::shared_ptr
我的 MFC 应用程序中有一个简单的图像缓存类,用于跟踪从文件系统加载的图像:
typedef boost::shared_ptr<Gdiplus::Image> ImagePtr;
typedef std::map<std::string, ImagePtr> ImageMap;
每当按文件名请求图像时,就会进行查找,或者如果已经加载,则返回相应的 ImagePtr 。
当我退出应用程序时会出现问题,并且共享指针被破坏。我在 checked_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!!
}
GDI+ 是否为我管理这些对象?如果是这样,我需要对我的shared_ptr做什么,这样它就不会调用delete?或者还有什么不对劲的地方吗?
提前致谢!
I have a simple Image cache class in my MFC application, to keep track of images loaded from the file system:
typedef boost::shared_ptr<Gdiplus::Image> ImagePtr;
typedef std::map<std::string, ImagePtr> ImageMap;
Whenever an image is requested by file name, a look up is done, or if it is already loaded, the appropriate ImagePtr is returned.
The problem occurs when I exit my application, and the shared pointer gets destructed. I get an access violation here, in checked_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!!
}
Is GDI+ managing these objects for me? If so, what do I need to do to my shared_ptr so that it doesn't call delete? Or is something else awry?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是在指针被销毁之前调用 GdiplusShutdown 的症状。
That might be a symptom of calling
GdiplusShutdown
before the pointers are destroyed.