"QOpenGLWidget: Failed to create context" and "composeAndFlush: QOpenGLContext creation failed" and "composeAndFlush: makeCurrent() failed"

I can run Slicer if I download binaries, but when I try to build from sources and then run it, I am getting errors. Any thoughts on what I should do differently? I get these errors whether I build using Qt-5.12.9 or Qt-5.15.0. I am using ITK current sources from github. The output I get is:

Switch to module:  "Welcome"
QOpenGLWidget: Failed to create context
QOpenGLWidget: Failed to create context
QOpenGLWidget: Failed to create context
QOpenGLWidget: Failed to create context
composeAndFlush: QOpenGLContext creation failed
composeAndFlush: makeCurrent() failed

… with that last one repeated ad infinitum – I gave up after more than 10^6 occurrences.

Do you mean you are using Slicer current source (latest master version) from github?
Does Slicer start at all?
Could you copy here your application log (menu: Help / Report a bug)?
What operating system do you use?
Are you using a physical computer directly (or some virtual machine or a physical computer via remote desktop)?
Does it make any difference if you build a package, install it, and run it?

Thank you for your response. I am still stuck. :frowning:

I am using the latest ITK sources (master branch) from github and setting the SHELL environment variable ITK_DIR to the build directory for that. I am also using the latest Slicer sources (master branch) from github.

Slicer puts up a box to show that it is starting, which then goes away. Then it puts up a box to show that it is loading things, which then goes away. Then it starts to draw what I assume is to be the Slicer scene, but it gets only as far as an outline, and the error messages begin. I do not get menus such as the “Help” menu.

I am using Ubuntu 20.04 with the very latest patches. I am running on my physical laptop. Unfortunately, I do not know what you mean by “package” in “build a package, install it, and run it”. Are you talking about an add on for Slicer? – not sure how that is relevant.

I tried yet another version of Qt, this time Qt-5.11.3. If I try to launch Qt apps (regardless of Slicer) I get errors. I did not try this with the other versions of Qt, but these errors could be relevant:

qSetGlobalQHashSeed: forced seed value is not 0, cannot guarantee that the hashing functions will produce a stable value.qt3ds.trace_info: Studio:  "/home/lee.newberg/Qt-5.11.3/Tools/Qt3DStudio/bin/Qt3DStudio"
qt3ds.trace_info: Version:  "2.7.0"

Unable to select suitable OpenGL context
Warning: No factory found for device 'WebAssembly Device' of type 'WebAssemblyDeviceType'.
Warning: Unable to restore Qt version 'Qt4ProjectManager.QtVersion.WebAssembly' stored in /home/lee.newberg/.config/QtProject/qtcreator/qtversion.xml.

Errors at startup:

    QmlDesigner

        Plugin initialization failed: Cannot create OpenGL context.

    QmlProfiler

        Plugin initialization failed: Cannot create OpenGL context.

    QtCreator starts but says:

        /usr/lib/jvm/java-8-openjdk-amd64/

        Java settings have errors.

       JDK path not is a valid JDK root folder

Would it help if, instead of using a fresh download of a Qt-5 version, I instead use the Qt5 directory from the Slicer binaries download: Slicer-4.11.0-2020-06-17-linux-amd64/lib/Slicer-4.11/cmake/Qt5

That is, for the Slicer build I could start with
cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DQt5_DIR:PATH=/home/lee.newberg/Support/Slicer-4.11.0-2020-06-17-linux-amd64/lib/Slicer-4.11/cmake/Qt5 ../Slicer

I do not know what you mean by “package” in “build a package, install it, and run it”.

I suspect @lassoan asked if downloading preview version of Slicer from https://download.slicer.org works as expected.

from github and setting the SHELL environment variable ITK_DIR to the build directory for that

How did you build ITK ? Is it linked against a different VTK build tree than the one used in Slicer ?

I instead use the Qt5 directory from the Slicer binaries download

This will not work, we are not distributing a SDK with the Slicer installer.

qSetGlobalQHashSeed: forced seed value is not 0, cannot guarantee that the hashing functions will produce a stable value.qt3ds.trace_info: Studio: "/home/lee.newberg/Qt-5.11.3/Tools/Qt3DStudio/bin/Qt3DStudio

Are you using Qt3DStudio in any way ? I am not sure why this message is showing up.

How did you build ITK ? Is it linked against a different VTK build tree than the one used in Slicer ?

Almost surely it is using a different tree! I will try unsetting the ITK_DIR shell environment variable to see if that helps.

Are you using Qt3DStudio in any way ? I am not sure why this message is showing up.

No, I have no need for Qt3DStudio. After the downloader finishes retrieving Qt5, its last step is to ask me if I want to launch Qt3DStudio and other programs. I let it do that and got the errors. I mentioned the errors in the hope that they would be useful clues.

Hi @Lee_Newberg - my suggestion would be to get a working Slicer build using the default config from Slicer master. Then change the config to point to the version of ITK you want to test. This way you know it will be built against Slicer’s VTK.

Thank you @pieper. Unfortunately, it is not a new ITK that I want to test, but a new Slicer. (I shouldn’t have been using ITK_DIR in the first place.) Hopefully, my build of Slicer master branch (without ITK_DIR set) will work, … and then I can try my Slicer branch.

1 Like

I meant creating a Slicer installation package by building PACKAGE target and installing it (on linux, just unzipping) and trying to use that. To see if any problems are due to differences in the build/install tree.

Rebuilding Slicer (master branch) into Slicer-SuperBuild-Debug-5.15.0 (or other Qt5 version) with the ITK_DIR shell environment variable not set (so that Slicer will use whatever ITK it wants rather than my override) nonetheless gives the same errors as above regardless of the Qt-5 version that I use.

I am giving a try with “make package” in the Slicer-build directory.

Do you have issue running the preview build downloaded from https://download.slicer.org ?

unsetting the ITK_DIR shell environment variable to see if that helps.

Could you copy here the command you use to configure Slicer ? (the goal here is to make sure you are building against Qt5 you installed by passing Qt5_DIR?)

Could you share the result of the following command ?

cd /path/to/Slicer-SuperBuild/Slicer-build
cat CMakeCache.txt | grep "^Qt5"

Qt3DStudio […] I let it do that and got the errors. I mentioned the errors in the hope that they would be useful clues.

Are you saying that that the error you reported above happen during install of Qt or when Slicer is starting up ?

Do you have issue running the preview build downloaded from https://download.slicer.org ?

I downloaded Slicer-4.10.2-linux-amd64.tar.gz, unpacked it, and that runs fine.

Could you copy here the command you use to configure Slicer ? (the goal here is to make sure you are building against Qt5 you installed by passing Qt5_DIR ?)

Sometimes I delete all *.o files in the ~/git/Slicer-SuperBuild-Debug-5.15.0 hierarchy before re-running the following.

cd ~/git/Slicer-SuperBuild-Debug-5.15.0
cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DQt5_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5 ../Slicer
make -j12 -k
make

cat CMakeCache.txt | grep “^Qt5”

Qt5Core_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5Core
Qt5DBus_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5DBus
Qt5Designer_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5Designer
Qt5Gui_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5Gui
Qt5Multimedia_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5Multimedia
Qt5Network_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5Network
Qt5OpenGL_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5OpenGL
Qt5Positioning_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5Positioning
Qt5PrintSupport_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5PrintSupport
Qt5QmlModels_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5QmlModels
Qt5Qml_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5Qml
Qt5QuickWidgets_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5QuickWidgets
Qt5Quick_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5Quick
Qt5Script_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5Script
Qt5Sql_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5Sql
Qt5Svg_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5Svg
Qt5Test_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5Test
Qt5UiPlugin_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5UiPlugin
Qt5UiTools_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5UiTools
Qt5WebChannel_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5WebChannel
Qt5WebEngineCore_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5WebEngineCore
Qt5WebEngineWidgets_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5WebEngineWidgets
Qt5WebEngine_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5WebEngine
Qt5Widgets_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5Widgets
Qt5X11Extras_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5X11Extras
Qt5XmlPatterns_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5XmlPatterns
Qt5Xml_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5Xml
Qt5_DIR:PATH=/home/lee.newberg/Support/Qt-5.15.0/5.15.0/gcc_64/lib/cmake/Qt5

Are you saying that that the error you reported above happen during install of Qt or when Slicer is starting up ?

I apologize for the earlier post that had errors from several soures in one post. The errors I get from running the Slicer that I have built from the master branch are the messages:

Switch to module:  "Welcome"
QOpenGLWidget: Failed to create context
QOpenGLWidget: Failed to create context
QOpenGLWidget: Failed to create context
QOpenGLWidget: Failed to create context
composeAndFlush: QOpenGLContext creation failed
composeAndFlush: makeCurrent() failed

… where that last one is produced an arbitrarily large number of times.

Great. What about the Preview build?

There are two types of download available, the Stable and the Preview.

While not relevant in this specific example, note that only deleting the *.o wouldn’t be enough if you already configured against a different version of ITK by passing option like -DITK_DIR:PATH=/path/to/different/ITK-build

Also worth noting that setting shell variable like ITK_DIR or generally speaking <proj>_DIR will have no effect.

No worry, thanks for taking the time to clarify and for helping us understand what is happening :slightly_smiling_face: :pray:

+1 to that!

Another note about the build system, in my experience it’s often best to bite the bullet and just rm -rf * in the superbuild directory if I think the configuration is in any way inconsistent. I know the build process takes forever but it puts you on solid ground for debugging. Sometimes you can get away with just deleting, say python* or ITK*.

While not relevant in this specific example, note that only deleting the *.o wouldn’t be enough if you already configured against a different version of ITK by passing option like -DITK_DIR:PATH=/path/to/different/ITK-build

I never did set ITK_DIR via the cmake command line so that may not have been an issue after all, despite that I had been setting the shell environment variable ITK_DIR.

There are two types of download available, the Stable and the Preview .

Thank you for clarifying that. The preview build does not work for me. I went back to the stable build and now that does not work either – which represents a regression for me, as that worked well enough a few weeks ago for me to go through a number of tutorials.

So, my problem does not seem to be a problem with building from 3D Slicer sources, but instead a problem with my general operating system configuration. I will go back to the general installation pages and getting started pages for 3D Slicer and try to figure out what I need to change on my Ubuntu 20.04 system.

It was a very long trek to a very easy destination … rebooting did the trick. I can now run 3D Slicer stable and preview releases as well as a version built from 3D Slicer sources.

1 Like

Out of curiosity, what was the original motivation behind setting this shell variable ? What led you to do so ?

By better understanding the reasoning, may be we could improve the documentation or message reported at configuration time.

I had the setting of the ITK_DIR shell variable in my ~/.bashrc because I was concurrently working on an ITK Module and the build for the module needed to know where it could find the base ITK. At this point, I have pulled the setting of the variable out of my ~/.bashrc file and am setting the variable only in terminal sessions where I am working with the ITK module.