C++ XTree 在退出时崩溃,map/set 迭代器不可取消引用
C++ XTree crash on exit, map/set iterator not dereferencable
我有一些静态 类,里面有 std::map,一切正常,但是当我退出程序时,它崩溃并出现错误 "map/set iterator not dereferencable"。
这是地图:
struct DataSegment_P { std::string type; };
template <typename T> struct DataSegment : public DataSegment_P{ T value; };
static std::map<std::string, DataSegment_P*> data;
另外两个:
static std::map<std::string, std::shared_ptr<sf::Texture>> textures;
static std::map<std::pair<std::string, std::vector<int>>, std::shared_ptr<sf::Sprite>> sprites;
最后一个:
struct Asset {
std::map<std::string, std::string> values;
};
static std::map<std::string, std::vector<std::shared_ptr<Asset>>> assets;
我无法真正将整个代码粘贴到此处,因为它有数千行长,但我正在按应有的方式清除地图。
好的,我找到问题了。抱歉,您无法猜到,所以我只是指出问题所在,如果有人像我一样可以解决它。
我正在使用 SFML,我刚刚发现您不能使用其中带有 sf::RenderWindow 的智能指针。这就是导致崩溃的原因。
我有一些静态 类,里面有 std::map,一切正常,但是当我退出程序时,它崩溃并出现错误 "map/set iterator not dereferencable"。
这是地图:
struct DataSegment_P { std::string type; };
template <typename T> struct DataSegment : public DataSegment_P{ T value; };
static std::map<std::string, DataSegment_P*> data;
另外两个:
static std::map<std::string, std::shared_ptr<sf::Texture>> textures;
static std::map<std::pair<std::string, std::vector<int>>, std::shared_ptr<sf::Sprite>> sprites;
最后一个:
struct Asset {
std::map<std::string, std::string> values;
};
static std::map<std::string, std::vector<std::shared_ptr<Asset>>> assets;
我无法真正将整个代码粘贴到此处,因为它有数千行长,但我正在按应有的方式清除地图。
好的,我找到问题了。抱歉,您无法猜到,所以我只是指出问题所在,如果有人像我一样可以解决它。
我正在使用 SFML,我刚刚发现您不能使用其中带有 sf::RenderWindow 的智能指针。这就是导致崩溃的原因。