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

Author Topic: Strange problem with sf::Window and multiple threads  (Read 1912 times)

0 Members and 1 Guest are viewing this topic.

marek3571

  • Newbie
  • *
  • Posts: 5
    • View Profile
Strange problem with sf::Window and multiple threads
« on: June 17, 2011, 07:56:03 am »
Hi,
I keep getting a runtime error when trying to create a window with SFML 2.0 when the class itself was constructed on a different thread.

Code: [Select]

class testThread : public MyThread    //not derived from sf::Thread
{
public:
testThread() : foo(), MyThread() {  }    //thread starts upon construction
void run()
{
foo.Create(sf::VideoMode(800, 600), "Test Window");
foo.Close();
}
private:
sf::Window foo;
};


When I try to run this, it crashes in sf::Window::Close() on the line
Code: [Select]
delete myContext; with the error  Unhandled exception at 0x000007fef35cf78f (sfml-window-d-2.dll) in SFML test.exe: 0xC0000005: Access violation reading location 0xffffffffffffffff."

However, I found that if I added
Code: [Select]
sf::Window bar; right before foo.Create(), the whole thing worked. What am I doing wrong???

marek3571

  • Newbie
  • *
  • Posts: 5
    • View Profile
Strange problem with sf::Window and multiple threads
« Reply #1 on: June 17, 2011, 08:02:39 am »
Well, i just looked a little closer and discovered that the problem is actually the way i handled my threads. The constructor was still running when foo.Create() was called.

 

anything