Hi All,
I'm experimenting with multiple windows. As per the guidelines I'm creating each window in it's own thread and handling the events within that thread context. However the event queue appears to be generic between the windows. What this means is that the events being triggered in one window are sometimes handled in another window.
I have a small test app here that creates two windows. Sometimes when closing the second window the first window will process the event. It's not limited to that event but all events.
Not included in the source for simplicity I have added a call to XInitThreads() as there appears to be some thread safety issues surrounding the xcb implementation and suggestions indicate that it should be added.
I'm testing on a Linux system so wondering if I'm either doing something stupid (very open to that fact!) or there is a genuine problem in the underlying implementation. I tried forcing the thread creation to be synchronous, just in case there were issues around that, but it has not helped.
When mousing over only one of the windows I get this type of output,
Event from window 1
Event from window 2
Event from window 2
Event from window 2
Event from window 1
Event from window 2
Event from window 1
Event from window 1
Event from window 2
Event from window 2
Event from window 1
Event from window 2
I'm working from the git repo, last commit was
commit d53338298ab56c41a4bd5d065001dfcfe223deef
Author: Lukas Dürrenberger <eXpl0it3r@sfml-dev.org>
Date: Wed Mar 11 08:46:40 2015 +0100
"uname -a" for OS
Linux 3.13.0-39-generic #66-Ubuntu SMP Tue Oct 28 13:30:27 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
#include <SFML/Window.hpp>
class Chart
{
public:
Chart( void );
~Chart( void );
void wait( void );
private:
static void mainWindowThread( void *threadData );
sf::Thread *mainWindowThread_;
static int windowNumber_;
};
int Chart::windowNumber_ = 0;
Chart::Chart( void )
{
mainWindowThread_ = new sf::Thread( mainWindowThread, this );
mainWindowThread_->launch();
}
Chart::~Chart( void )
{
if( mainWindowThread_ != NULL )
{
mainWindowThread_->wait();
delete mainWindowThread_;
}
}
void Chart::wait( void )
{
mainWindowThread_->wait();
}
void Chart::mainWindowThread( void *threadData )
{
char title[50];
Chart *chart = (Chart *)threadData;
sf::Event event;
int num=++windowNumber_;
snprintf( title, 50, "Window %d", windowNumber_ );
sf::Window window(sf::VideoMode(800, 600), title);
// run the program as long as the window is open
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
while (window.waitEvent(event))
{
printf( "Event from window %d\n", num );
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
}
}
}
int main( int argc, const char *argv[] )
{
Chart chart1;
Chart chart2;
chart1.wait();
return( 0 );
}