c++ - SFML - 运行时检查失败 #2 - 变量周围的堆栈已损坏,每次运行程序时都会发生
问题描述
我正在使用 Visual Studio 2017,我已经设置了链接器,包括在调试和发布配置中。每次我尝试运行代码时,它都会向我抛出围绕各种变量的损坏堆栈的异常。无论是“设置”、“窗口”等。
我运行了两个代码,结果都相同:
#include<SFML/Graphics.hpp>
#include<iostream>
int main()
{
sf::ContextSettings settings;
settings.majorVersion = 3;
settings.minorVersion = 3;
settings.depthBits = 24;
settings.antialiasingLevel = 16;
sf::RenderWindow window(sf::VideoMode(800, 600), "Game", sf::Style::Default);
window.setActive(true);
window.setFramerateLimit(60);
while (window.isOpen())
{
window.clear(sf::Color::Black);
window.display();
sf::Event ev;
while (window.pollEvent(ev))
{
if (ev.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
{
window.close();
}
}
}
return 0;
}
第二个:
#include<iostream>
#include<SFML/Graphics.hpp>
int main()
{
using namespace sf;
RenderTexture texture;
texture.create(800, 600);
texture.clear(Color::Black);
texture.display();
texture.getTexture().copyToImage().saveToFile("D:\output\asd.bmp");
return 0;
}
两个代码都抛出类似的异常,第一个程序抛出:
运行时检查失败 #2 - 变量“设置”周围的堆栈已损坏。
运行时检查失败 #2 - 变量“window”周围的堆栈已损坏。
第二个扔
运行时检查失败 #2 - 变量“纹理”周围的堆栈已损坏。
当我在调试器中按“继续”时,它会将我指向带有未处理异常的 gs_report:
Project2.exe 中 0x00A36859 处的未处理异常:堆栈 cookie 检测代码检测到基于堆栈的缓冲区溢出。
是代码有问题,还是我的设置有问题?
解决方案
推荐阅读
- python - 熊猫和 HTML 标签
- javascript - Turbolinks - 为什么 turbolinks 不适用于 jquery 或 javascript?
- php - 抓取外部 json 存储到数据库中
- swift4 - iOS HealthKit - 如何获得绝对最新的当前心率,例如手表心率并发症?
- go - 动态设置结构的键和值
- php - php循环运行命令
- c# - 抛出异常:Microsoft.Azure.Devices.Client.dll 中的“System.MissingMethodException”
- javascript - 为什么通知 API 不适用于 chrome for android?
- html - CSS Web Safe Font 中的字母间距错误
- spring - Spring Batch Stream 重启问题?