c++ - VS2012 调试中 SFML 变量周围的损坏堆栈

标签 c++ visual-studio-2012 sfml

我正在使用 Visual Studio 2012。在 Debug模式下编译时,以下代码会导致错误

Run-Time Check Failure #2 - Stack around the variable 'line' was corrupted.

#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
  std::cout << "Please ignore this box\n";

  sf::Font font;

  if (!font.loadFromFile("font.ttf"))
    std::cout << "Font not loaded\n";

  sf::RenderWindow window(sf::VideoMode(1000, 800),
                          "Test Window",
                          sf::Style::Titlebar | sf::Style::Close);

  if (!window.isOpen())
    std::cout << "Problem creating window\n";

  while (window.isOpen()) {
    sf::Event event;

    while (window.pollEvent(event)) {
      if (event.type == sf::Event::Closed)
        window.close();
    }

    window.clear(sf::Color::Black);

    sf::RectangleShape line(sf::Vector2f(2, 750));
    line.setFillColor(sf::Color::White);
    line.setPosition(700, 25);

    window.draw(line);
    window.display();
  }

  return 0;
}

在 Release 模式下编译可以解决问题,但我想知道是什么原因造成的,是否有解决方法。

谢谢。

最佳答案

引用 the official tutorial 的红色部分:

It is important to link to the libraries that match the configuration: "sfml-xxx-d.lib" for Debug, and "sfml-xxx.lib" for Release. A bad mix may result in crashes.

关于c++ - VS2012 调试中 SFML 变量周围的损坏堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23122860/

相关文章:

c++ - 如何删除双向链表中的第一个节点?

c++ - Boost Graph Library astar和导航网格

c++ - 在 SFML 中由 RectangleShape 制成的 Tilegrid 给出转换错误

c++ - 在我的循环中实现 Delta 计时

c++ - 如何检索数据类型的大小?

c++ - 错误 : prototype does not match any in class

c++ - mac 上的 Opencv 包含错误

c++ - 为什么这会在 ideone 和 visual studio 中显示运行时错误,但在代码块中却没有?

visual-studio-2012 - Visual Studio 2012 HelpViewer 2.0 仍然损坏 : location specified installing content invalid

visual-studio - 哪些平台将支持Visual Studio 11?