SFML community forums

Help => Window => Topic started by: Zakkle on December 02, 2019, 01:46:30 pm

Title: Multiple Windows, Multiple Threads
Post by: Zakkle on December 02, 2019, 01:46:30 pm
Aight, now before you get your pitchforks and torches out, all I'm trying to do, right now, is unblock the program.

This is basically how my program is setup:
main() -> Lobby (GTK) -> Login (GTK)
\/
Closes and returns to main()
\/
main() -> Main game window (SFML) -> Control panel (GTK) -> Tool window (GTK) + Pallet Window (SFML)

Now, I have not been able to get the control panel to open without blocking the SFML window, so I called the GTK window in a new thread. I can also get the secondary GTK window to open, as well as the SFML pallet window.

At this point, all events in the secondary windows are all working fine.  The issue comes in when clicking back on the main window.  I get crashes and random errors.

The real killer for me is that I thought I had this issue resolved, completely, because it was working flawlessly on all windows, no matter what I tested. 
Code: [Select]
Gdk-Message: Fatal IO error 0 (Success) on X server :1.
Code: [Select]
[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.
xcb_io.c:260: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
Code: [Select]
Failed to get the window attributes
Failed to query GLX version, limited to legacy context creation
[xcb] Extra reply data still left in queue
[xcb] This is most likely caused by a broken X extension library
[xcb] Aborting, sorry about that.
: xcb_io.c:580: _XReply: Assertion `!xcb_xlib_extra_reply_data_left' failed.
/.../codelite-exec.sh: line 3:  8166 Aborted                 (core dumped) ${command}

I've done some searching and people have suggested adding a call to XInitThreads() in the main() function, but that didn't do any good.

I've done experimentation with various things, such as using GTK's .show() instead of app->run(), I've used .setActive(true/false), I've used std::thread.detach(), but none of the combinations yielded any results other than crashing the program sooner, blocking the other windows, or causing everything to hang.

Any idea why it randomly works one time, but then I get four different outcomes of errors?

All I want is to be able to use all of my windows without any blocking.
Title: Re: Multiple Windows, Multiple Threads
Post by: Zakkle on December 03, 2019, 01:02:56 pm
k, so this did fix it, after all:
main.cpp
#include <X11/Xlib.h>
...
main(...) {
    XInitThreads();
    ...
}
 
The reason it wasn't working for me, at first, is because when you link it using -lX11, it needs to be earlier in the list.

After much testing, all of my multithreading is working (100% of the time, not just hit and miss anymore).

[EDIT NOTE: Previous last edit was  "« Last Edit: December 03, 2019, 01:04:51 pm by Zakkle »" ]
[EDIT] I have abandoned the threads used by SFML because I have found an efficient way to use std::thread.  That said, I have nothing against SFML's threads, per se, but the only reason I was using them in my projects was because that was the only thing available in my project until std::thread was created, and then it took a long time for me to adapt to the standard.