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

Author Topic: [Linux] [SFML2] Another Threading Question ...  (Read 3918 times)

0 Members and 1 Guest are viewing this topic.

priiice

  • Newbie
  • *
  • Posts: 5
    • View Profile
[Linux] [SFML2] Another Threading Question ...
« on: March 13, 2011, 12:01:51 am »
First off I want to say that I'm really enjoying SFML after having tried several other windowing solutions over the past months.

As per this thread, I'm trying to separate rendering from input (and yes, I'm confident this is something I want to do).  I create and poll for events within the main thread and do all OpenGL'y things in another.  However like this second thread, Linux is complaining about the same things.  I'm pretty sure I've read through just about every post regarding separation of rendering from logic, but cannot fathom what I'm doing wrong.

I was originally receiving these errors in SFML 1.6 and moved up to 2.0 hoping it would fix everything.  It did not. :(

The errors: (Each time I make and run, I get one of these three errors.  The order and frequency with which I receive the three appears to be non-deterministic.)

Quote

xcb_io.c:221: poll_for_event: Assertion `(((long) (event_sequence) - (long) (dpy->request)) <= 0)' failed.

xcb_io.c:140: dequeue_pending_request: Assertion `req == dpy->xcb->pending_requests' failed.

*** glibc detected *** double free or corruption (fasttop): 0x000000000160c710 ***
======= Backtrace: =========
/lib/libc.so.6(+0x72985)[0x7fe7452cb985]
/lib/libc.so.6(cfree+0x6c)[0x7fe7452d08bc]
/usr/lib/libX11.so.6(_XReply+0x200)[0x7fe7448c1520]
//usr/lib64/opengl/xorg-x11/lib/libGL.so.1(+0x54832)[0x7fe744e13832]
//usr/lib64/opengl/xorg-x11/lib/libGL.so.1(+0x52659)[0x7fe744e11659]
/usr/lib64/dri/i965_dri.so(+0x39377)[0x7fe742883377]
/usr/lib64/dri/i965_dri.so(+0x39985)[0x7fe742883985]
/usr/lib64/dri/i965_dri.so(+0x389ec)[0x7fe7428829ec]
./pax[0x401fb2]
/usr/lib/libsfml-system.so.2.0(_ZN2sf4priv10ThreadImpl10EntryPointEPv+0x18)[0x7fe745f9ee98]
/lib/libpthread.so.0(+0x6d4c)[0x7fe745042d4c]
/lib/libc.so.6(clone+0x6d)[0x7fe74532fc5d]



The header:

Code: [Select]

#ifndef FRAMEWORK_ENGINE_HH_
#define FRAMEWORK_ENGINE_HH_

namespace sf { class Window; }
namespace sf { class Input; }
namespace sf { class Event; }

class Engine {
public:

Engine(void);
~Engine(void);

void start(void);

private:

void render(void);
void handleEvent(sf::Event const* event);
void handleKeyPressed(sf::Event const* event);
void handleKeyReleased(sf::Event const* event);

bool running;
sf::Window* surface;

};
#endif // FRAMEWORK_ENGINE_HH_


And implementation:

Code: [Select]

Engine::Engine(void) : running(false), surface(0) {}

Engine::~Engine(void)
{
if (surface) delete surface;
}

void Engine::handleEvent(sf::Event const* event)
{
switch(event->Type) {
case sf::Event::Closed: running = false; break;
default: break;
}
}

void Engine::render(void)
{

surface->SetActive(true);

glClearColor(0.0f,0.0f,0.0f,0.0f);
glViewport(0,0,640,480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,640.0,480.0,0.0,1.0,-1.0);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
glLoadIdentity();

while(running == true) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glBegin(GL_QUADS);
glColor3f(1.0f,0.0f,0.0f); glVertex3f(0.0f,0.0f,0.0f);
glColor3f(1.0f,1.0f,0.0f); glVertex3f(100.0f,0.0f,0.0f);
glColor3f(1.0f,0.0f,1.0f); glVertex3f(100.0f,100.0f,0.0f);
glColor3f(1.0f,1.0f,1.0f); glVertex3f(0.0f,100.0f,0.0f);
glEnd();
surface->Display();
}

surface->SetActive(false);

}

void Engine::start(void)
{

running = true;
surface = new sf::Window(sf::VideoMode(640,480,32),"OpenGL Demo");
surface->SetActive(false);

sf::Thread thread(&Engine::render,this);
thread.Launch();

while (running == true) {
sf::Event event;
while (surface->GetEvent(event)) handleEvent(&event);
}

thread.Wait();

}


Any help would be very much appreciated.  Thanks!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[Linux] [SFML2] Another Threading Question ...
« Reply #1 on: March 13, 2011, 09:43:48 am »
Your code looks ok, but... it's hard to tell without the full picture. Maybe you could simplify your code and show us a complete and minimal example that reproduces the problem?
Laurent Gomila - SFML developer

priiice

  • Newbie
  • *
  • Posts: 5
    • View Profile
[Linux] [SFML2] Another Threading Question ...
« Reply #2 on: March 13, 2011, 10:19:51 am »
Oops, sorry.  I had run a first pass minimalization but here's a second go.  I hope this is better.  It removes just about everything while maintaining the functionality I want to use (namely threading member functions).  The following snippets should give a full working example that produces the errors I'm seeing on my end.  Cutting out the extra rendering and event handling squashed the 3rd error but the first two still remain.

Errors:

Quote

xcb_io.c:221: poll_for_event: Assertion `(((long) (event_sequence) - (long) (dpy->request)) <= 0)' failed.

xcb_io.c:140: dequeue_pending_request: Assertion `req == dpy->xcb->pending_requests' failed.


Header (engine.hh):

Code: [Select]

#ifndef FRAMEWORK_ENGINE_HH_
#define FRAMEWORK_ENGINE_HH_

namespace sf { class Window; }

class Engine {
public:

Engine(void);
void start(void);

private:

void render(void);

bool running;
sf::Window* surface;

};

#endif // FRAMEWORK_ENGINE_HH_


Implementation (engine.cc):

Code: [Select]

#include <SFML/Window.hpp>
#include "framework/engine.hh"

Engine::Engine(void) : running(false), surface(0) {}

void Engine::render(void)
{
surface->SetActive(true);

while(running == true) {
surface->Display();
}

surface->SetActive(false);
}

void Engine::start(void)
{
running = true;
surface = new sf::Window(sf::VideoMode(640,480,32),"OpenGL Demo");
surface->SetActive(false);

sf::Thread thread(&Engine::render,this);
thread.Launch();

while (running == true) {
sf::Event event;
while (surface->GetEvent(event)) {}
}

}


And finally (main.cc):

Code: [Select]

#include "framework/engine.hh"

int main(int argc, char** argv)
{
Engine engine; engine.start();
return 0xdead;
}


If there's anything else I can do to help, let me know.  I'm very eager to get this working. :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[Linux] [SFML2] Another Threading Question ...
« Reply #3 on: March 13, 2011, 11:05:08 am »
It's ok, thank you. I don't see anything wrong. Do you know which function call trigger these errors?
Laurent Gomila - SFML developer

priiice

  • Newbie
  • *
  • Posts: 5
    • View Profile
[Linux] [SFML2] Another Threading Question ...
« Reply #4 on: March 13, 2011, 11:35:27 am »
Weird.  If I comment out the Display call, I can incrementally add back in the event handling and it works.  Conversely, I can comment GetEvent and incrementally add in the rendering and it works.  So exclusively one of either Display or GetEvent in the code works fine. e.g. both of the following work:

Thread #1: Create window, loop calling GetEvent
Thread #2: Empty infinite loop

Thread #1: Create window, empty infinite loop
Thread #2: loop calling Display

However as soon as I try to use both simultaneously, I receive the aforementioned errors.

Any thoughts? :-/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[Linux] [SFML2] Another Threading Question ...
« Reply #5 on: March 13, 2011, 07:51:26 pm »
Have you tried the same code on Windows or OS X?
Laurent Gomila - SFML developer

priiice

  • Newbie
  • *
  • Posts: 5
    • View Profile
[Linux] [SFML2] Another Threading Question ...
« Reply #6 on: March 14, 2011, 03:20:00 pm »
Sorry it took me a while to respond, I didn't have any alternate computers readily available.  I tested the same code under Windows and it works.  Don't have a Mac on hand so cannot verify whether the same problem persists in OS-X.  It would seem to be a Linux issue though.  What would you recommend?  I can dump any system info from the Linux box into this thread if you feel it might be helpful?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[Linux] [SFML2] Another Threading Question ...
« Reply #7 on: March 14, 2011, 03:56:03 pm »
I have no idea what's going on, but let's see that after I commit the fix for the ATI bg, which wil also solve a lot of context-related problems.
Laurent Gomila - SFML developer

priiice

  • Newbie
  • *
  • Posts: 5
    • View Profile
[Linux] [SFML2] Another Threading Question ...
« Reply #8 on: March 14, 2011, 03:58:41 pm »
Sure, no problem.  I'll be sure to check out the source and try again once you do.

Lukas W

  • Newbie
  • *
  • Posts: 2
    • View Profile
Problem still exists
« Reply #9 on: October 25, 2012, 10:09:23 pm »
Hi,

I'm very sorry to bring up this really old thread. However, the problem described in this topic still exists.
In my own project, I get the these two error messages, too:
Quote
xcb_io.c:140: dequeue_pending_request: Assertion `req == dpy->xcb->pending_requests' failed.
xcb_io.c:571: _XReply: Assertion `(((long) (req->sequence) - (long) (dpy->request)) <= 0)' failed.

For my project, I used the code from this tutorial: http://www.sfml-dev.org/tutorials/2.0/window-opengl.php


Compiling and running the code priiice provided I get those very similar errors:
Quote
xcb_io.c:515: _XReply: Assertion `!dpy->xcb->reply_data' failed.
xcb_io.c:668: _XRead: Assertion `dpy->xcb->reply_data != ((void *)0)' failed.
xcb_io.c:221: poll_for_event: Assertion `(((long) (event_sequence) - (long) (dpy->request)) <= 0)' failed.

My code is crashing on Window::setActive(true) in render(), priiice's code is crashing on surface->pollEvent(event) in Engine::start() (line 58).

Everything runs perfectly fine in Windows, though.

Thanks

Edit: Apart from this, SFML really rocks so far!  ;)
« Last Edit: October 25, 2012, 10:11:13 pm by Lukas W »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: [Linux] [SFML2] Another Threading Question ...
« Reply #10 on: October 25, 2012, 10:13:03 pm »
Can you try to call XInitThreads at the beginning of your program? (you'll need to include the Xlib header)

Which version of SFML do you use? You must use the latest sources, not the RC, to have the latest corrections.
Laurent Gomila - SFML developer

Lukas W

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: [Linux] [SFML2] Another Threading Question ...
« Reply #11 on: October 26, 2012, 06:05:24 pm »
Hi and thanks for your answer. I compiled and used the latest revision at that time, forgot to say that.
Calling really XInitThreads fixes the problem, thank you :)

But now I experience some significant display lag when using V-Sync while still measuring ~60 fps. Works fine when rendering in the main thread though.
Edit: Should I open a new topic about this?
« Last Edit: October 26, 2012, 09:18:22 pm by Lukas W »

 

anything