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

Author Topic: Threading errors (Something to do with object disposal?)  (Read 4359 times)

0 Members and 1 Guest are viewing this topic.

cpolymeris

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
    • Email
Threading errors (Something to do with object disposal?)
« on: July 11, 2013, 03:59:08 am »
Hello, all. I have been running into these threading errors:

Code: [Select]
[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.
mono: ../../src/xcb_io.c:179: dequeue_pending_request: Assertion `!xcb_xlib_unknown_req_in_deq' failed.
Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) SFML.Graphics.RenderWindow.sfRenderWindow_getViewport (intptr,intptr) <IL 0x00012, 0xffffffff>
  at SFML.Graphics.RenderWindow.GetViewport (SFML.Graphics.View) [0x00001] in /home/camilo/Proyectos/Pax/Libraries/SFML.Net/src/Graphics/RenderWindow.cs:332
  at Gwen.Renderer.SFML.StartClip () [0x000a2] in /home/camilo/Proyectos/Pax/Libraries/GwenCS/Gwen.Renderer.SFML/Renderer/SFML.cs:415
  at Gwen.Control.Base.RenderRecursive (Gwen.Skin.Base,System.Drawing.Rectangle) [0x00056] in /home/camilo/Proyectos/Pax/Libraries/GwenCS/Gwen/Control/Base.cs:1146
  at Gwen.Control.Base.DoRender (Gwen.Skin.Base) [0x00045] in /home/camilo/Proyectos/Pax/Libraries/GwenCS/Gwen/Control/Base.cs:1113
  at Gwen.Control.Canvas.RenderCanvas () [0x0006d] in /home/camilo/Proyectos/Pax/Libraries/GwenCS/Gwen/Control/Canvas.cs:127
  at Pax.Client.MainWindow.Update () [0x0002a] in /home/camilo/Proyectos/Pax/Programs/Pax.Client/MainWindow.cs:82
  at Pax.Client.MainClass.Main (string[]) [0x0000d] in /home/camilo/Proyectos/Pax/Programs/Pax.Client/Main.cs:34
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

Native stacktrace:

    /usr/bin/mono() [0x4a9301]
    /lib/x86_64-linux-gnu/libpthread.so.0(+0xf210) [0x7fdb9ed30210]
    /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x35) [0x7fdb9e9aa1e5]
    /lib/x86_64-linux-gnu/libc.so.6(abort+0x148) [0x7fdb9e9ad398]
    /lib/x86_64-linux-gnu/libc.so.6(+0x2e272) [0x7fdb9e9a3272]
    /lib/x86_64-linux-gnu/libc.so.6(+0x2e322) [0x7fdb9e9a3322]
    /usr/lib/x86_64-linux-gnu/libX11.so.6(+0x433dc) [0x7fdb96e803dc]
    /usr/lib/x86_64-linux-gnu/libX11.so.6(_XReply+0x23b) [0x7fdb96e8121b]
    /usr/lib/x86_64-linux-gnu/libX11.so.6(_XGetWindowAttributes+0xa4) [0x7fdb96e68974]
    /usr/lib/x86_64-linux-gnu/libX11.so.6(XGetWindowAttributes+0x31) [0x7fdb96e68ae1]
    /usr/lib/libsfml-window.so.2(+0xd31d) [0x7fdb9c3fa31d]
    /usr/lib/libsfml-window.so.2(_ZNK2sf6Window7getSizeEv+0x15) [0x7fdb9c3f6165]
    /usr/lib/libsfml-graphics.so.2(_ZNK2sf12RenderWindow7getSizeEv+0x9) [0x7fdb9c62b389]
    /usr/lib/libsfml-graphics.so.2(_ZNK2sf12RenderTarget11getViewportERKNS_4ViewE+0x12) [0x7fdb9c62a8e2]
    /usr/lib/libcsfml-graphics.so.2(sfRenderWindow_getViewport+0xd) [0x7fdb9c85104d]
    [0x40b1db98]

Further down it lists the threads that are running, but marks the 1st (main) thread as active, if I understand correctly.

Code: [Select]
* 1    Thread 0x7fdb9f833740 (LWP 12975) "mono" 0x00007fdb9ed2fe07 in __libc_waitpid (pid=<optimized out>, stat_loc=<optimized out>, options=<optimized out>) at ../sysdeps/unix/sysv/linux/waitpid.c:40

I have found one "solution", but I don't know what I might be breaking. To comment out the Dispose in SFML.Net's ObjectBase destructor (or whatever it's called in C#).

public abstract class ObjectBase : IDisposable
{
//...
        ~ObjectBase()
        {
            //Dispose(false);
        }
//...
}
 

So, my suspcion is, the finalizer disposes something the main thread is still using. But I have no idea what it could be, and why it happens. Any hints?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Threading errors (Something to do with object disposal?)
« Reply #1 on: July 11, 2013, 03:12:33 pm »
Quote
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called

I am assuming you are running SFML.NET on linux through mono, in this case I would see if there is a way to call XInitThreads through mono's .NET framework. See this thread for more information.

Quote
I have found one "solution", but I don't know what I might be breaking. To comment out the Dispose in SFML.Net's ObjectBase destructor (or whatever it's called in C#).

public abstract class ObjectBase : IDisposable
{
//...
        ~ObjectBase()
        {
            //Dispose(false);
        }
//...
}
 

So, my suspcion is, the finalizer disposes something the main thread is still using. But I have no idea what it could be, and why it happens. Any hints?

See this thread for more information about that destructor. Basically if you call sfmlobject.Dispose() instead of letting the object go out of scope then the destructor will be called with true and then SFML will not attempt to mess with the OpenGL contexts. I am personally against setting a context active and then inactivating it just because an object goes out of scope since in my tests I haven't found any problems when I changed it.

Just be sure that you do not totally comment out the Dispose call or else you will end up with an unmanaged memory leak.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

cpolymeris

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
    • Email
Re: Threading errors (Something to do with object disposal?)
« Reply #2 on: July 11, 2013, 11:53:35 pm »
Thanks for your help, zsbzsb!

Calling XInitThreads does indeed solve the issue (see below for future reference). I am concerned the problem might still show up later, though, as I don't really understand why that destructor causes problem. But I will bookmark this thread, so I can come back, if necessary.

class MainClass
{
        public static void Main (string[] args)
        {
                XInitThreads();
                using (MainWindow win = new MainWindow ())
                {
                        //...
                }
        }

        [DllImport("X11")]
        extern public static int XInitThreads();
}

 

anything