【发布时间】:2016-12-12 08:24:52
【问题描述】:
我已经研究这个问题一段时间了,我想我已经缩小了我的问题范围。
这是错误输出
Critical error detected c0000374
Duke's Army.exe has triggered a breakpoint.
Exception thrown at 0x77E49841 (ntdll.dll) in Duke's Army.exe: 0xC0000374: A heap has been corrupted (parameters: 0x77E7C8D0).
Unhandled exception at 0x77E49841 (ntdll.dll) in Duke's Army.exe: 0xC0000374: A heap has been corrupted (parameters: 0x77E7C8D0).
The program '[14436] Duke's Army.exe' has exited with code 0 (0x0).
调用栈如下
ucrtbased.dll!0f8aa672() Unknown
[Frames below may be incorrect and/or missing, no symbols loaded for ucrtbased.dll]
[External Code]
> Duke's Army.exe!Tile::Tile() Line 19 C++
[External Code]
Duke's Army.exe!Map::Map(int w, int h) Line 70 C++
Duke's Army.exe!MapGenerator::init(int w, int h) Line 37 C++
Duke's Army.exe!MapGenerator::MapGenerator(int w, int h) Line 13 C++
Duke's Army.exe!PlayGameState::PlayGameState(Game * g) Line 13 C++
Duke's Army.exe!main() Line 11 C++
[External Code]
其他答案建议删除未正确声明的静态成员或类似的东西。但是,在(假定的)受影响的类中,有一个静态向量,我找不到删除的方法。有什么建议吗?
[这是我认为发生错误的类] (调用栈第19行是默认构造函数定义的开始)
平铺.h
class Tile
{
public:
static std::vector<Tile> tiles;
// Constructors and methods...
// Method used in constructors to add to static tiles
void Tile::init(const std::string& n, const sf::Color& c) {
this->name = n;
this->color = c;
tiles.push_back(*this);
}
Tile(std::string n, sf::Color c) {
init(n, c);
};
Tile() {
init("bounds", sf::Color::Black);
}
const static Tile wall;
const static Tile floor;
const static Tile bounds;
const static float TILE_SIZE;
};
静态成员在 Tile.cpp 中声明
std::vector<Tile> Tile::tiles = std::vector<Tile>(3);
const Tile Tile::wall("wall", sf::Color::White);
const Tile Tile::floor("floor", sf::Color::Green);
const Tile Tile::bounds;
const float Tile::TILE_SIZE = 16.f;
【问题讨论】:
-
我认为问题不会出现在任何声明代码中。检查你的构造函数和方法。
-
const Tile Tile::xxxx应该是const Tile::xxxx -
@Jean-FrançoisFabre 嗯。我不这么认为。这些成员(其中三个)是
Tile对象,对于Tile类是静态的(这是允许的)。 -
调试器会出现这种情况吗?什么是调用栈?
-
这发生在调试器中。我将发布带有答案的调用堆栈。
标签: c++ c++11 static global sfml