我正在使用SFML。我试图在屏幕上写一些文字。每当我关闭应用程序时,我都会得到"堆叠变量'数据'被腐蚀了#34;错误,但我没有看到代码有任何问题。
#include <SFML\Graphics.hpp>
using namespace sf;
int main() {
RenderWindow win(VideoMode(640, 480), "", Style::None);
Font lucida;
lucida.loadFromFile("lucon.ttf");
Text data;
data.setCharacterSize(12);
data.setColor(Color(180, 180, 180));
data.setFont(lucida);
data.setPosition(Vector2f(10, 10));
data.setStyle(Text::Bold);
data.setString("test");
Event evt;
double dt = 0.f;
Clock clock;
double dwticks = clock.getElapsedTime().asSeconds();
double dwnewticks = 0.f;
while (win.isOpen()) {
if (win.pollEvent(evt)) {
if (Keyboard::isKeyPressed(Keyboard::Key::Escape)) win.close();
}
else {
dwnewticks = clock.getElapsedTime().asSeconds();
dt = dwnewticks > dwticks ? (dwnewticks - dwticks) / 4000.f : 0.f;
dwticks = dwnewticks;
win.clear(Color(0, 0, 0));
win.draw(data);
win.display();
}
}
return 0;
}
答案 0 :(得分:0)
更改此行:
if (Keyboard::isKeyPressed(Keyboard::Key::Escape)) win.close();
要:
if (Keyboard::isKeyPressed(Keyboard::Key::Escape)){
win.close();
break;
}