Hi guys,
I've recently discovered a very disturbing "bug" -- if it's any. I'll try to describe the problem:
I'm using two threads in my application: the first polls SFML events, handles them and calls then another class (called "State") to render the scene. The second thread is inside that State class. It's launched when the State is created, waits a second and just creates an sf::Image and loads an image.
While the image gets loaded, it's possible that the first thread is just rendering the scene/clearing the window/displaying the contents.
So, my first question is: Is SFML threadsafe enough so that I don't have to manage that myself?
What happens is: when you start the program often enough (depends on luck, I guess...), it freezes. Backtrace:
#0 0x00007f8d9c74e1f4 in __lll_lock_wait () from /lib/libpthread.so.0
#1 0x00007f8d9c749acb in _L_lock_312 () from /lib/libpthread.so.0
#2 0x00007f8d9c7494d1 in pthread_mutex_lock () from /lib/libpthread.so.0
#3 0x00007f8d9dbff3c9 in ?? () from /usr/lib/libGL.so.1
#4 0x00007f8d9ac71d98 in ?? () from /usr/lib/libGLcore.so.1
#5 0x00007f8d9ac2caaa in ?? () from /usr/lib/libGLcore.so.1
#6 0x00007f8d9a8f133b in ?? () from /usr/lib/libGLcore.so.1
#7 0x00007f8d9d4a215e in sf::RenderTarget::Clear () from /usr/lib/libsfml-graphics.so.1.6
#8 0x000000000040354f in Tilechat::Run ()
#9 0x0000000000402f3b in main ()
So the last call before going to system libraries is sf::RenderTarget::Clear(). Then it's diving into OpenGL, where an infinite lock happens. This *normally* tells us it's a bug in OpenGL. But since I haven't learned the SFML source code good enough, that'd be also a possibility.
In the worst case, that "bug" even kills my X-Server! The log tells me this:
Backtrace:
560 0: /usr/bin/X(xf86SigHandler+0x6a) [0x47898a]
561 1: /lib/libc.so.6 [0x7f4c034470f0]
562 2: /usr/lib/xorg/modules/drivers//nvidia_drv.so(_nv001853X+0x6) [0x7f4bffbdf756]
563 3: /usr/lib/xorg/modules/drivers//nvidia_drv.so [0x7f4bffd5561c]
564 4: /usr/lib/xorg/modules/drivers//nvidia_drv.so [0x7f4bffd6c499]
565 5: /usr/bin/X(Dispatch+0x342) [0x44f7e2]
566 6: /usr/bin/X(main+0x4a5) [0x436bd5]
567 7: /lib/libc.so.6(__libc_start_main+0xe6) [0x7f4c034335a6]
568 8: /usr/bin/X [0x435e99]
nvidia_drv.so, that really sounds bad. But again, I don't know in which context and whatever. It's of course possible the bug starts very sooner and just kicks in at driver level.
So far, so good. Here's a ZIP containing source code for a minimal reproduction setup:
*click* . Please keep in mind that the sources come from a rather full-blown game.
I've stripped them down as much as possible to isolate the bug.
Okay, then something else, which maybe has something todo with the described bug above:
In my full game, I've also got one critical bug: *Sometimes* (not always!) the program crashes with an GLXBadContext error code. That ALWAYS happens when 1. using sf::Image::LoadFromFile() OR 2. doing something with the loaded image after that.
If that helps, I can post more source code, but since it's a big project, it would take some more time to understand it. So I thought I'd just point you in the right direction at first to see if you know anything that can help.
My system setup is:
Debian GNU/Linux on a 64 Bit AMD CPU
SFML version: SVN r1177 (latest)
Graphics driver: nvidia, 185.18.14 (latest)
Kernel: 2.6.26
If you need any information, please let me know. It's important for me to get that thing fixed, since it stops my programming entirely.