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

Author Topic: Random Crashing in Multi-threaded Project.  (Read 2695 times)

0 Members and 1 Guest are viewing this topic.

Ammorth

  • Newbie
  • *
  • Posts: 2
    • View Profile
Random Crashing in Multi-threaded Project.
« on: July 02, 2013, 07:11:07 am »
So I started working with SFML for a personal project and ran into a weird issue with SFML and controlling the rendering in a second thread.  I get random crashes from X and/or xcb, usually involving an unknown request in the queue or a request in the queue during a dequeue.

Using the current build of SFML from git (as of 9:55pm PDT) on master branch.  Using Linux Mint 14 with all packages updated and kernel 3.5.0-17-generic.

build command is
g++ src/engine.cpp -Wall -std=c++0x -o3 -lsfml-graphics -lsfml-window -lsfml-system -o build/engine

This is the trimmed down version which causes the problems:

#include <SFML/Graphics.hpp>

void renderThread_entry(sf::RenderWindow* window)
{
    while (window->isOpen())
    {
        window->clear();
        window->display();
    }
}


int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "XCB Error Test");
    window.setActive(false);
       
    sf::Thread renderThread(&renderThread_entry, &window);
    renderThread.launch();

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

    renderThread.wait();

    return 0;
}

Commenting out all the event stuff in the main function stops the random crashing.  Add a sleep timer to the drawing thread to show that it doesn't happen on program start, but rather after a random period of time.

Some of the specific errors I get.

Quote
[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
engine: ../../src/xcb_io.c:179: dequeue_pending_request: Assertion `!xcb_xlib_unknown_req_in_deq' failed.
Aborted

Quote
[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server ":0.0"
      after 1900 requests (1900 known processed) with 1 events remaining.
engine: ../../src/xcb_io.c:179: dequeue_pending_request: Assertion `!xcb_xlib_unknown_req_in_deq' failed.
Aborted

Quote
X Error of failed request:  BadIDChoice (invalid resource ID chosen for this connection)
  Major opcode of failed request:  139 (XFIXES)
  Minor opcode of failed request:  5 (XFixesCreateRegion)
  Resource id in failed request:  0x3e00064
  Serial number of failed request:  435
  Current serial number in output stream:  436

Again, these are "random" crashes in that they happen after a random period of time.  If it doesn't crash right away, either wait a bit or close it and try running again.

Thanks for the help.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Random Crashing in Multi-threaded Project.
« Reply #1 on: July 02, 2013, 07:57:10 am »
You must call XInitThreads, it's not done in SFML.
« Last Edit: July 02, 2013, 08:31:23 am by Laurent »
Laurent Gomila - SFML developer

Ammorth

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Random Crashing in Multi-threaded Project.
« Reply #2 on: July 02, 2013, 08:22:58 am »
Ahh, that fixed it.  I had assumed it was covered already in SFML.  Thanks for the speedy reply!

 

anything