I've been porting Ostrich Riders to the SFML 2.3.2. I've got it working but soon after starting it complains a with:
“Ostrich Riders 0.6.1” is not responding.
You may choose to wait a short while for it to continue or force the application to quit entirely.
If you wait everything works fine. I'd like to stop the message from appearing. I played around with the sample from
here. Just had to fix the path to the font. That still gets the message. Suspecting that anything using pollEvent gets the error, I switched to waitEvent. No error but obviously doesn't display properly. I moved the waiting for events in a separate thread. That works for a while. Eventually you get:
[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
Using Fedora 23, is it possible to avoid the "not responding" message window? Do any examples using pollEvent avoid this message? If you must use waitEvent is it possible to use it in a separate thread from the window drawing without causing it to crash?
Here is a simple example I tried with a thread. I've tried both drawing in the main thread and waiting for events in the main thread. Neither made a difference. (Don't worry about the use of globals or anything. I'm just doing a proof of concept which oviously hasn't worked.)
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <cstdlib>
#include <ctime>
enum State { Closed, Normal } ;
void update_normal(sf::RenderWindow & w ) ;
const std::string fontLocation = "/usr/share/fonts/liberation/LiberationSans-Regular.ttf" ;
sf::Font font ;
State state;
sf::RenderWindow *win;
struct ConsumeEvent
{
public:
void operator()();
};
void ConsumeEvent::operator()()
{
while ( win->isOpen() )
{
if ( state == Closed )
{
win->close() ;
continue ;
}
win->clear() ;
update_normal(*win) ;
win->display() ;
}
}
int main()
{
std::srand(std::time(0)) ;
sf::RenderWindow window( sf::VideoMode(800,600), "Pause me!") ;
window.setFramerateLimit(60);
win = &window;
state = Normal;
if (!font.loadFromFile(fontLocation))
return 0 ;
ConsumeEvent c;
sf::Thread t(c);
t.launch();
sf::Event event ;
while ( win->waitEvent(event) )
{
switch(event.type)
{
case sf::Event::Closed:
state = Closed ;
break ;
default:
break ;
}
if (state == Closed)
break;
}
t.wait();
}
void update_normal(sf::RenderWindow & w )
{
static sf::Text text("Running!", font) ;
text.setColor( sf::Color(63, 127, 127) ) ;
text.setPosition( 200 + std::rand() % 50, 275 + std::rand() %50 ) ;
w.draw(text) ;
}