【发布时间】:2020-12-08 18:45:52
【问题描述】:
我是 sfml 和 c++ 的新手。我有一个项目使用 sfml 库来绘制图形,但是当我向我的程序添加一个额外的线程时,它无法执行线程内的代码。这是我的代码:(请帮助我!)
#include <SFML\Graphics.hpp>
#include <SFML\window.hpp>
#include <SFML\system.hpp>
#include <iostream>
#include <thread>
#include <chrono>
using namespace std;
int h(sf::RenderWindow* win){
//do something
win->close();
this_thread::sleep_for(chrono::milliseconds(10));
return 0;
}
int main(){
sf::RenderWindow window(sf::VideoMode(800,600),"My window");
thread t1(h,&window);
_sleep(10000000);
t1.join();
return 0;
}
【问题讨论】:
-
当它"...执行代码失败..."时会发生什么?
-
它什么也没做。
-
尝试将
sf::RenderWindow window(...);移动到h()。 -
在我的真实程序中它必须在 main 中,我别无选择
-
因为它是一个游戏,我应该同时做几个图形
标签: c++ visual-c++ sfml