SFML community forums

Help => System => Topic started by: gmysu on October 23, 2012, 08:09:44 pm

Title: sfml threads and wxwidgets
Post by: gmysu on October 23, 2012, 08:09:44 pm
Hello everybody,

I wanted to integrate my console application written with sfml network package with wxwidgets.
However when I use sf::thread in my code, whole think freezes. with exact the same code without gui lib it works fine. Also, when i comment out the threads code in gui app, it also works fine. Any ideas?
Title: Re: sfml threads and wxwidgets
Post by: eXpl0it3r on October 23, 2012, 11:12:46 pm
Show us the code as a minimal example, we are no magicians that can read your mind and using threads often isn't a trivial thing to do, since there are many possibilities to do things wrong. ;)
Title: Re: sfml threads and wxwidgets
Post by: FRex on October 23, 2012, 11:25:10 pm
Did you maybe create thread on the stack and it went out of scope thus calling wait on it and making the thread that pushed it out of scope wait for it to finish?
Title: Re: sfml threads and wxwidgets
Post by: gmysu on October 24, 2012, 10:40:20 am
The thing is i just wanted to add wxwidgets window with debug information such as UPS, number of players etc. to my server app, as the console output isnt very clear to deal with in this case.

In the following code, app object is my server class. Important thing is I dont want to change anything inside it, so that without any effort i can still compile it without gui in another project.

bool cApp::OnInit()
{
        // Create an instance of our frame, or window
        cMainFrame *mainWin = new cMainFrame(_("server"), wxDefaultPosition, wxSize(600, 500));
        mainWin->Show(true); // show the window
        SetTopWindow(mainWin); // and finally, set it as the main window

        app = new App();
        app->go(); //init server class

        return true;
}
 

This is my thread initialization code, it is called just before the main loop inside App class.

sf::Thread thread(&App::acceptConnections,this);
thread.launch();
 

Thanks for your time:)

Title: AW: sfml threads and wxwidgets
Post by: eXpl0it3r on October 24, 2012, 10:46:17 am
If you just want to display some information, then why do you 'have to' use wxWidget?
Just use everything that SFML provides...
Not that this immedietly will solve the problem, but it makes it easier.

Your posted code doesn't help at all, because it's neither complete nor minimal, i.e. we've no idea what you actually do...
Title: Re: sfml threads and wxwidgets
Post by: gmysu on October 24, 2012, 12:48:53 pm
Oh my threads went out of scope. Fixed:)
Title: Re: sfml threads and wxwidgets
Post by: FRex on October 24, 2012, 04:47:50 pm
Oh my threads went out of scope. Fixed:)
Did you maybe create thread on the stack and it went out of scope thus calling wait on it and making the thread that pushed it out of scope wait for it to finish?
:P