Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML 2.5.0 - Crashes when using sf::Clipboard::getString() in Linux  (Read 3510 times)

0 Members and 1 Guest are viewing this topic.

Tonberry

  • Newbie
  • *
  • Posts: 1
    • View Profile
Hello!

I have a problem when using sf::Clipboard::getString(). I'm calling it every frame, to sync the clipbaord of the X-server with an internal clipboard. It works fine for a while, but crashes after a small amount of time (usually 5 seconds to more than 60 seconds). When it crashes I get one of two error messages that occur:

Quote
[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.
MyApp: xcb_io.c:259: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.

OR

Quote
XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server ":0"
after 5340 requests (5340 known processed) with 0 events remaining.

After some investigation I found that the first error happens during a call for XNextEvent in the SFML code
String ClipboardImpl::getString()
{
    if(!is_init)
        initClipboard();

    if(is_fail || is_host)
        return string;

    // Dangerous! Wipes all previous events!
    XSync(display, true);
    XConvertSelection(display, selection, utf8_text, atom_text, window, CurrentTime);

    XEvent event;

    pthread_mutex_lock(&mutex);
    XNextEvent(display, &event); //<-- Crashes here when getting the first listed error message.
    pthread_mutex_unlock(&mutex);

   ...
 

When calling the clipboard in my code, I simply do:
    string osStr = "";

    sf::String osSfStr = sf::Clipboard::getString();
    osStr = osSfStr;
 

This code is called inside a update sequence with a lot of other things.

I have a suspicion that the error happens due to the multi-threading process in sf::Clipboard, but I don't know for sure.

Quote
My system information:
OS: Manjaro 17.1.10 Hakoila
Kernel: x86_64 Linux 4.9.96-1-MANJARO
GCC-version: 7.3.0

I'm really hyped for the clipboard functionality, and it works great before it crashes. If you have any tips, I'd be glad to hear. Otherwise, I hope this helps finding the error :P

For now I'm implementing a temporary Clipboard class to get clipboard text from the X-server.

- Robin.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
I can reproduce this error with this code:

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "Test");

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        sf::err() << sf::Clipboard::getString().toAnsiString() << std::endl;

        window.clear();
        window.display();
    }
}

Will work on a fix.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
This issue should be fixed with PR #1437.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Tonberry, does the linked PR fix your issue?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything