在SFML(版本2.1)上遇到一些问题。
尝试在两个独立的线程上创建两个sf :: RenderWindow实例。应用程序工作一段时间(时间量不是恒定的),然后最终会因断言而崩溃:
testapp: ../../src/xcb_conn.c:186: write_vec: Assertion `!c->out.queue_len' failed.
测试代码:
#include <iostream>
#include <thread>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <X11/Xlib.h>
void WindowOne ()
{
sf::RenderWindow* wnd = new sf::RenderWindow (sf::VideoMode(800,600),
"Window 1");
while (wnd->isOpen())
{
sf::Event event;
while (wnd->pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
wnd->close();
break;
default:
break;
}
}
wnd->clear(sf::Color::White);
wnd->display();
}
delete wnd;
}
void WindowTwo ()
{
sf::RenderWindow* wnd = new sf::RenderWindow (sf::VideoMode(800,600),
"Window 2");
while (wnd->isOpen())
{
sf::Event event;
while (wnd->pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
wnd->close();
break;
default:
break;
}
}
wnd->clear(sf::Color::White);
wnd->display();
}
delete wnd;
}
int main(int argc, char** argv) {
XInitThreads();
std::thread thread1 (WindowOne);
std::thread thread2 (WindowTwo);
thread1.join();
thread2.join();
return 0;
}
请帮助我找出,我做错了什么,或者我甚至可以做这些事情。
修改
忘记提到它崩溃了:
wnd->display();