【发布时间】:2015-05-03 17:45:36
【问题描述】:
这是我认为是问题原因的类中的一个函数:
void Game::processGameScreen()
{
cout << "\nGAME PROCESS STARTED";
tetriminoInPlay = new Tetrimino;
tetriminoOnDeck = new Tetrimino;
int count = 0;
while (window.isOpen() && gameWell.topReached() == false)
{
//check for events and create tetrimino pointers
sf::Event event;
while (window.pollEvent(event)) {
//check for arrow key presses
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Up)
{
tetriminoInPlay->rotateRight();
if (gameWell.tetriminoFit(*tetriminoInPlay) == false)
tetriminoInPlay->rotateLeft();
}
else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Left)
{
tetriminoInPlay->moveLeft();
if (gameWell.tetriminoFit(*tetriminoInPlay) == false)
tetriminoInPlay->moveRight();
}
else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Right)
{
tetriminoInPlay->moveRight();
if (gameWell.tetriminoFit(*tetriminoInPlay) == false)
tetriminoInPlay->moveLeft();
}
else if (event.type == sf::Event::Closed)
window.close();
//counter to move pieces down
cout << "\n" << count;
if (count % 15 == 0 ) {
cout << "\nMOVING DOWN";
tetriminoInPlay->moveDown();
//check if it fits
if (gameWell.tetriminoFit(*tetriminoInPlay) == false) {
tetriminoInPlay->moveUp();
gameWell.addTetriminoToWell(*tetriminoOnDeck);
delete tetriminoInPlay;
score = score + gameWell.clearFullRows(); //add combo scoring later
//check for game over
if (gameWell.topReached() == false) {
tetriminoInPlay = tetriminoOnDeck;
tetriminoInPlay->setLocation(0,4);
delete tetriminoOnDeck;
tetriminoOnDeck = new Tetrimino;
}
}
}
count++;
//clear window, draw well, tetro, window.display
window.clear(sf::Color::White);
//draw tetriminoOnDeck !!!Figure out where to draw this at some point!!!
//drawTetrimino(tetriminoOnDeck, LAYOUT_BOARD_TOP, LAYOUT_BOARD_LEFT, BLOCK_SIZE_PIXELS);
drawWell(gameWell, LAYOUT_BOARD_TOP, LAYOUT_BOARD_LEFT, BLOCK_SIZE_PIXELS);
drawTetrimino(tetriminoInPlay, LAYOUT_BOARD_TOP, LAYOUT_BOARD_LEFT, BLOCK_SIZE_PIXELS);
drawScore(score, 50, 50);
window.display();
}
}
}
我相信问题出在某个地方的指针上。我无法找到确切的问题,甚至无法确定问题发生在什么情况下,因为它发生的时间似乎不一致。
这也出现在错误中:
表达式:_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
如果这很重要,我正在使用 SFML 图形库。
【问题讨论】:
-
该断言通常意味着您在某处损坏了内存。通常写在数组的边界之外。如果您在调试器中运行它,您将能够看到代码中的哪一行触发了问题。这并不意味着您破坏了记忆,但给您一个开始寻找的地方会很有帮助。
标签: c++ debugging pointers sfml assertion