gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 06:56:25 25 4
gpt4 key购买 nike

我正在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com