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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - priiice

Pages: [1]
1
Window / [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!

Pages: [1]