C++ 映射中的特定键导致访问冲突错误,仅在没有gdb的情况下显示
我正在使用贴图来存储角色的位图坐标,以便在从精灵工作表渲染角色时使用。 坐标贴图定义为C++ 映射中的特定键导致访问冲突错误,仅在没有gdb的情况下显示,c++,stl,C++,Stl,我正在使用贴图来存储角色的位图坐标,以便在从精灵工作表渲染角色时使用。 坐标贴图定义为 typedef std::array<double,4> Coordinates; typedef std::unordered_map<char, Coordinates> CharacterMapping; 然后坐标被提供给我创建的类,(Drawable是一个容器类,带有指向表示可绘制对象的shape对象的指针,shape是表示图形形状的抽象类,SpriteText是shape的
typedef std::array<double,4> Coordinates;
typedef std::unordered_map<char, Coordinates> CharacterMapping;
然后坐标被提供给我创建的类,(Drawable是一个容器类,带有指向表示可绘制对象的shape对象的指针,shape是表示图形形状的抽象类,SpriteText是shape的子类)
只要我省略空格字符的坐标或在gdb下运行程序,这就可以很好地工作。
如果程序只是简单地运行,它会在可绘制的构造函数行上出现-1073741819访问冲突错误代码。(通过在控制台中打印每一行来标识,但不进入构造函数本身)
删除行、用任何其他字符(如“\”)替换“”或只是在gdb下运行它似乎可以解决这个问题。为什么在调用完全独立的类构造函数时,键值的更改会影响或导致访问冲突错误?为什么它在使用gdb时不显示
委员会成员:
SpriteText::SpriteText(const Vector& position, Graphics::Texture* const texture,
const CharacterMapping& coordinates, const std::string& text) :
Shape(position) {
_charDrawer = new CharSprite(position, Vector(1,1), texture, coordinates, 'c');
_text_info.line_info_r = NULL;
setText(text);
}
CharSprite::CharSprite(const Vector& position, const Vector& dimensions,
Texture* const texture, const CharacterMapping& coordinates,
const char& character):
Sprite(position,dimensions,texture){
setSpriteCoordinates(coordinates);
setCurrentCharacter(character);
}
Drawable::Drawable(World* world, Shape* shape):
GameObject(world){
setWorld(world);
_shape = shape;
_drawableFlags = Drawable::Flags::BOUND_BY_WORLD;
}
Windows xp、mingw和g++。为什么所有这些
都是新的s?没有它们,生活难道还不够艰难吗?在spritetext上,它似乎是必要的,因为形状是抽象的。在CharacterMapping上,它主要用于测试目的,使用非指针初始化的CharacterMapping可以得到相同的结果。Drawable将其自身添加到世界中,它作为构造函数参数提供,并且在退出函数时它将被删除(这不是渲染循环,所以它会很糟糕)。您使用什么开关编译?尝试使用-O0-ggdb-fno省略帧指针-Wall-Werror-fno严格别名编译,看看是否在gdb下仍然看不到它。另外,请显示(至少)SpriteText和可绘制因子的指纹。@kfsone添加了这些因子。我使用了-g-std=gnu++0x-Wall
。使用新的开关(减-Werror
,有几个-Wunused变量错误)提供了相同的结果,gdb中没有错误,普通运行中有错误。
SpriteText* spriteTextShape = new SpriteText(Vector(100,700), // position
ltrTex, // the bitmap
*charMap, // the map
"hello world\nalso you\n1. it is ok, dont worry!\n2. what?"); // some text
Drawable *drw = new Drawable(world, // a container of all objects
spriteTextShape); // the shape
SpriteText::SpriteText(const Vector& position, Graphics::Texture* const texture,
const CharacterMapping& coordinates, const std::string& text) :
Shape(position) {
_charDrawer = new CharSprite(position, Vector(1,1), texture, coordinates, 'c');
_text_info.line_info_r = NULL;
setText(text);
}
CharSprite::CharSprite(const Vector& position, const Vector& dimensions,
Texture* const texture, const CharacterMapping& coordinates,
const char& character):
Sprite(position,dimensions,texture){
setSpriteCoordinates(coordinates);
setCurrentCharacter(character);
}
Drawable::Drawable(World* world, Shape* shape):
GameObject(world){
setWorld(world);
_shape = shape;
_drawableFlags = Drawable::Flags::BOUND_BY_WORLD;
}