Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED] Order of execution of QOffscreenSurface and QOpenGLContex.



  • I want to draw a image in the QOpenGLFramebufferObject and I use QOffscreenSurface for rendering in another thread without creating a QWindow.

    I wrote this part of code for initialize OpenGL context and on Windows all works fine.
    @
    m_surface.create();
    m_context = new QOpenGLContext(this);
    m_context->setFormat(m_surface.requestedFormat());
    m_context->create();
    m_context->makeCurrent(&m_surface);
    @

    But on my work Linux PC I have segfault in 2-nd row. And if I swap first two rows and run on Linux all works fine again.

    And question is "Why?". It's a bug or maybe I doing something wrong? I didn't find any information about order of execution for surface and context in the documentation.

    PS I don't run swapped version on Windows. And don't know whether it work.



  • Not sure about the crash, but be aware that creating (as in create()) a QOffscreenSurface outside the gui thread is wrong, at least on Windows. This is because on Windows the QOffscreenSuface is nothing but a hidden QWindow and a regular window surface. Creating QWindows outside the gui thread will lead to issues sooner or later so it must be avoided. In fact Qt 5.2.1 and newer will show a warning in this case. On Linux there is no such limitation, though, since there QOffscreenSurface is backed by a GLX or EGL pbuffer surface.



  • Do you mean that I should run create() from the gui thread and then I can create context object without issues?



  • Well, like I said I cannot be sure what causes the crash. But in any case, yes, call m_surface.create() on the gui thread instead.



  • Ok. Thanks.

    I'd like add that to call create() need after the a.exec() was called.


Log in to reply