dlopen(libGL.so) resolves to mesa rather than nvidia

Bug #941826 reported by Peter Würtz
104
This bug affects 23 people
Affects Status Importance Assigned to Milestone
NVIDIA Drivers Ubuntu
New
Undecided
Unassigned
mesa (Ubuntu)
Invalid
Undecided
Unassigned
nvidia-graphics-drivers-331-updates (Ubuntu)
Invalid
Undecided
Unassigned
nvidia-graphics-drivers-340 (Ubuntu)
Invalid
Undecided
Unassigned
pyqt5 (Ubuntu)
Invalid
Undecided
Unassigned
python-qt4 (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

I'm having trouble with a combination of NVIDIA + Python + Qt + Opengl.

I tried using a QGraphicsView on a QGLWidget. I'm getting a white window and errors like this these:
QGLShader: could not create shader
Vertex shader for simpleShaderProg (MainVertexShader &PositionOnlyVertexShader) failed to compile

This is an example application triggering the problem:
http://pastebin.com/R0aa8ejs

The 'same' program works flawlessly when using C++/Qt. I'm seeing the exact behavior when using PySide instead of PyQt4 by the way. I'm also seeing this error when trying the original demo application from python-qt4-doc. Also, calling
QtGui.QApplication.setGraphicsSystem("opengl")
produces the same errors.

I'm experiencing this problems on 11.10 and 12.04 with the ubuntu-provided nvidia drivers (where 12.04 includes the most recent driver for now). After installing the driver using the original NVidia installer, the applications work as expected.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in python-qt4 (Ubuntu):
status: New → Confirmed
Revision history for this message
Peter Würtz (pwuertz) wrote :

Still seeing this in 12.10

Revision history for this message
Peter Würtz (pwuertz) wrote :

Problem still exists in 13.10 and also affects QML/QtQuick applications on Qt5.

Revision history for this message
Peter Würtz (pwuertz) wrote :

Sorry, I meant QML/QtQuick applications on PyQt5.

Revision history for this message
Peter Würtz (pwuertz) wrote :

Workaround:
The shader creation problem completely vanishes when importing PyOpenGL additionally to PyQt. It doesn't even matter if it's imported before or after PyQt, just before the first shader is created.

When I add:
from OpenGL import GL
the example from my first post works.

Someone from the PyQt mailing list suggested that this is caused by an error when python dynamically loads the GL library.

summary: - OpenGL backend not working with Nvidia driver package
+ PyQt cannot compile shaders with Ubuntu's Nvidia drivers
Revision history for this message
Launchpad Janitor (janitor) wrote : Re: PyQt cannot compile shaders with Ubuntu's Nvidia drivers

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in pyqt5 (Ubuntu):
status: New → Confirmed
Revision history for this message
Dmitry Shachnev (mitya57) wrote :

As discussed in bug 1241988, this is rather an issue with drivers themselves.

affects: pyqt5 (Ubuntu) → nvidia-graphics-drivers-331-updates (Ubuntu)
Revision history for this message
Dmitry Shachnev (mitya57) wrote : Re: [Bug 941826] Re: PyQt cannot compile shaders with Ubuntu's Nvidia drivers

Might be related to bug 1248642.

Revision history for this message
Peter Würtz (pwuertz) wrote : Re: PyQt cannot compile shaders with Ubuntu's Nvidia drivers

Hm, this bug here existed already in 2012, whereas bug 1248642 is a regression from a change in binutils in 2013. Also, this missing libpthread.so.0 link problem shouldn't apply since the main application, python, is definitely linked to it:

$ objdump -pR /usr/bin/python | grep libpthread
  NEEDED libpthread.so.0

Revision history for this message
Peter Würtz (pwuertz) wrote :

Here is another, more minimalistic script that demonstrates the shader compilation bug on NVIDIA and its workaround.

Revision history for this message
Jörn Schönyan (joern-schoenyan) wrote :

I can confirm that bug in PyQt5/QML. I hope that it can be fixed, as I'm working on a project for future Lubuntu versions and want to get rid of additional dependencies (python3-opengl). Interesting: It doesn't seem to exist on hybrid notebooks a.k.a. Optimus in combination with bumblebee.

Revision history for this message
Scott Kitterman (kitterman) wrote :

Since this works fine on non-nvidia systems, why does anyone think this is anything other than a driver issue?

Revision history for this message
B. Clausius (barcc) wrote :

Since this works fine with Qt, why does anyone think this is anything other than a PyQt issue?

Revision history for this message
Scott Kitterman (kitterman) wrote : Re: [Bug 941826] Re: PyQt cannot compile shaders with Ubuntu's Nvidia drivers

On Tuesday, August 12, 2014 05:13:54 you wrote:
> Since this works fine with Qt, why does anyone think this is anything
> other than a PyQt issue?

OK, provide a working Qt test case to go with the PyQt test case already
provided and I'll see what upstream has to say.

Revision history for this message
Peter Würtz (pwuertz) wrote : Re: PyQt cannot compile shaders with Ubuntu's Nvidia drivers

Please also have a look at my example and workaround in #10. As described in #5, the problem seems to be an error when python dynamically loads the required opengl libraries. Unfortunately we still don't know what exactly goes wrong and why it only affects python qt bindings loading the ubuntu-packaged nvidia driver.

Revision history for this message
Peter Würtz (pwuertz) wrote :

Ok, I think I found the problem.

Apparently the PyQt application ends up loading the Mesa GL library (/usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0) instead of the NVidia driver (/usr/lib/nvidia-331/libGL.so.331.38) that is loaded when importing PyOpenGL first.

The difference seems to be the library name when calling dlopen(). PyOpenGL tries to import "libGL.so.1", whereas PyQt imports "libGL.so", without the ".1" suffix.

A simple C application calling dlopen() and checking /proc/<pid>/maps shows that "libGL.so" points to the Mesa driver, whereas "libGL.so.1" ends up loading the NVidia driver.

So this is a bug in Ubuntu's NVidia package I assume?

Revision history for this message
Peter Würtz (pwuertz) wrote :

The first entry of "libGL.so" in "ldconfig -p" points to "/usr/lib/x86_64-linux-gnu/libGL.so", which is a symlink to the mesa driver. After deleting that link pyqt works fine as expected. That symlink belongs to the "libgl1-mesa-dev" package and seems to overrule the libGL.so entries in ldconfig for the nvidia driver.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in mesa (Ubuntu):
status: New → Confirmed
Changed in pyqt5 (Ubuntu):
status: New → Confirmed
Revision history for this message
B. Clausius (barcc) wrote :

Thanks Peter Würtz! So it seems the workaround can be simplified to

import ctypes
ctypes.CDLL('libGL.so.1', ctypes.RTLD_GLOBAL)

or

import ctypes.util
ctypes.CDLL(ctypes.util.find_library('GL'), ctypes.RTLD_GLOBAL)

Changed in python-qt4 (Ubuntu):
status: Confirmed → Invalid
Changed in pyqt5 (Ubuntu):
status: Confirmed → Invalid
summary: - PyQt cannot compile shaders with Ubuntu's Nvidia drivers
+ dlopen(libGL.so) resolves to mesa rather than nvidia
Revision history for this message
Jörn Schönyan (joern-schoenyan) wrote :

barcc, that second approach won't work.

import ctypes
from ctypes import util
ctypes.CDLL(util.find_library('GL'), ctypes.RTLD_GLOBAL)

That should be better, but I can't reproduce the bug myself, likely because it's an Optimus notebook.

Revision history for this message
Peter Würtz (pwuertz) wrote :

*sigh* late 2015, still not fixed in Ubuntu

Revision history for this message
Thomas Karl Pietrowski (thopiekar) wrote :

Still here on Wily

Revision history for this message
JianFeng Liu (liujianfeng1994) wrote :

why not just dlopen libGL.so.1
I've mailed to the packager of nvidia driver in debian and got the answer: "pyqt should dlopen libGL.so.1".

Revision history for this message
Peter Würtz (pwuertz) wrote :

I don't even understand the argument. Lets turn it around/right again: Why not just dlopen libGL.so? Any application should be able to dlopen libGL.so.

"libGL.so" is the library name everyone agrees to and everyone expects to find, which is exactly why this file exists in the first place, doesn't it? One should expect that this primary library name points to the most reasonable and (before all else) WORKING OpenGL library. If a distribution decides to do some name mangling for maintaining multiple versions or vendors it is of course free to do so. Please name it "libGL.so.foo" or "libGl.so.bar" if you want, buy why is it necessary for pyqt to know about your naming decision and most importantly: Why is it necessary to stick with a broken(!) default configuration?

It baffles me that it took 4 years to boil it down to one line of not giving a damn.

Revision history for this message
kosti (ilayn) wrote :

Just to provide another user-case:

https://github.com/spyder-ide/spyder/issues/3226

I don't even understand the problem unfortunately.

Revision history for this message
ChenYunChih (cba840910) wrote :
Revision history for this message
Peter Würtz (pwuertz) wrote :

Still not fixed after almost 5 years. Problem and solution are well known.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in nvidia-graphics-drivers-340 (Ubuntu):
status: New → Confirmed
Revision history for this message
Tempuser (tempuser999) wrote :

Also there seems to be no interest in fixing this, for the record:

Problem and solution are still present/working in Ubuntu 17.10. and Nvidia driver 384.

Revision history for this message
Julian Gilbey (jdg) wrote :

I have found the source of the bug and provided a patch: see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=913287

Revision history for this message
Julian Gilbey (jdg) wrote :

And the Qt team are now working on implementing the patch, so this should be resolving in a forthcoming Qt release :-) See https://bugreports.qt.io/browse/QTBUG-71488

Timo Aaltonen (tjaalton)
Changed in mesa (Ubuntu):
status: Confirmed → Invalid
Changed in nvidia-graphics-drivers-331-updates (Ubuntu):
status: Confirmed → Invalid
Changed in nvidia-graphics-drivers-340 (Ubuntu):
status: Confirmed → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.