Hi all, 

I'm developing some code to display coordinate frames and links for robot 
arms for a class I teach on robotics. Myself and a TA used pyqtgraph 
successfully a few years ago with older versions of Ubuntu (20.04) and 
pyqtgraph. 

However, recently, when I tried to update the code for students to use with 
Ubuntu 22.04, Python 3.11, and using the VS code IDE, I get errors on the 
command line every time I try to render a GLMeshItem object and the display 
window only shows a blank grid. I thought that the inputs or data types for 
this object had changed. But the example provided in the library give the 
same error for any 3D mesh rendering.

I can reproduce a similar error with the basic example in the attached 
code.  This code gives the following error when I run it: 

   - QSocketNotifier: Can only be used with threads started with QThread
   /usr/lib/python3/dist-packages/pyqtgraph/opengl/GLViewWidget.py:260: 
   RuntimeWarning: 
   Traceback (most recent call last):
     File "/home/robotics/robotics_hw_2022/test_sphere_debug.py", line 30, 
   in <module>
       QtWidgets.QApplication.instance().exec_()
     File 
   "/usr/lib/python3/dist-packages/pyqtgraph/opengl/GLViewWidget.py", line 
   239, in paintGL
       self.drawItemTree(useItemNames=useItemNames)
     File 
   "/usr/lib/python3/dist-packages/pyqtgraph/opengl/GLViewWidget.py", line 
   271, in drawItemTree
       self.drawItemTree(i, useItemNames=useItemNames)
     File 
   "/usr/lib/python3/dist-packages/pyqtgraph/opengl/GLViewWidget.py", line 
   260, in drawItemTree
       debug.printExc()
     --- exception caught here ---
     File "/usr/lib/python3/dist-packages/OpenGL/latebind.py", line 43, in 
   __call__
       return self._finalCall( *args, **named )
   TypeError: 'NoneType' object is not callable
   During handling of the above exception, another exception occurred:
   Traceback (most recent call last):
     File 
   "/usr/lib/python3/dist-packages/pyqtgraph/opengl/GLViewWidget.py", line 
   257, in drawItemTree
       i.paint()
     File 
   "/usr/lib/python3/dist-packages/pyqtgraph/opengl/items/GLMeshItem.py", line 
   177, in paint
       glVertexPointerf(verts)
     File "/usr/lib/python3/dist-packages/OpenGL/latebind.py", line 47, in 
   __call__
       return self._finalCall( *args, **named )
     File "/usr/lib/python3/dist-packages/OpenGL/wrapper.py", line 626, in 
   wrapperCall
       storeValues(
     File "/usr/lib/python3/dist-packages/OpenGL/arrays/arrayhelpers.py", 
   line 156, in __call__
       contextdata.setValue( self.constant, pyArgs[self.pointerIndex] )
     File "/usr/lib/python3/dist-packages/OpenGL/contextdata.py", line 58, 
   in setValue
       context = getContext( context )
     File "/usr/lib/python3/dist-packages/OpenGL/contextdata.py", line 40, 
   in getContext
       raise error.Error(
   OpenGL.error.Error: Attempt to retrieve context when no valid context
     debug.printExc()
   Error while drawing item <pyqtgraph.opengl.items.GLMeshItem.GLMeshItem 
   object at 0x7efd483d1360>.
   /usr/lib/python3/dist-packages/pyqtgraph/opengl/GLViewWidget.py:260: 
   RuntimeWarning: 
   Traceback (most recent call last):
     File "/home/robotics/robotics_hw_2022/test_sphere_debug.py", line 30, 
   in <module>
       QtWidgets.QApplication.instance().exec_()
     File 
   "/usr/lib/python3/dist-packages/pyqtgraph/opengl/GLViewWidget.py", line 
   239, in paintGL
       self.drawItemTree(useItemNames=useItemNames)
     File 
   "/usr/lib/python3/dist-packages/pyqtgraph/opengl/GLViewWidget.py", line 
   271, in drawItemTree
       self.drawItemTree(i, useItemNames=useItemNames)
     File 
   "/usr/lib/python3/dist-packages/pyqtgraph/opengl/GLViewWidget.py", line 
   260, in drawItemTree
       debug.printExc()
     --- exception caught here ---
     File 
   "/usr/lib/python3/dist-packages/pyqtgraph/opengl/GLViewWidget.py", line 
   257, in drawItemTree
       i.paint()
     File 
   "/usr/lib/python3/dist-packages/pyqtgraph/opengl/items/GLMeshItem.py", line 
   177, in paint
       glVertexPointerf(verts)
     File "/usr/lib/python3/dist-packages/OpenGL/latebind.py", line 43, in 
   __call__
       return self._finalCall( *args, **named )
     File "/usr/lib/python3/dist-packages/OpenGL/wrapper.py", line 626, in 
   wrapperCall
       storeValues(
     File "/usr/lib/python3/dist-packages/OpenGL/arrays/arrayhelpers.py", 
   line 156, in __call__
       contextdata.setValue( self.constant, pyArgs[self.pointerIndex] )
     File "/usr/lib/python3/dist-packages/OpenGL/contextdata.py", line 58, 
   in setValue
       context = getContext( context )
     File "/usr/lib/python3/dist-packages/OpenGL/contextdata.py", line 40, 
   in getContext
       raise error.Error(
   OpenGL.error.Error: Attempt to retrieve context when no valid context
     debug.printExc()
   Error while drawing item <pyqtgraph.opengl.items.GLMeshItem.GLMeshItem 
   object at 0x7efd483d1360>.
   Error while drawing item <pyqtgraph.opengl.items.GLMeshItem.GLMeshItem 
   object at 0x7efd483d1360>.
   
A similar type of error happens with the 3D data examples provided in the 
library when running this code: 

   - import pyqtgraph.examples
   pyqtgraph.examples.run()


This error only seems to happen when running the code from within the VS 
Code IDE (even if I try to run it from the terminal within VS code). When 
running it from the normal command line, there's no problem. Any idea why 
this might be the case? Any suggestions of how to solve it? I have tried 
changing the python interpreter being used by VS code, but it doesn't make 
a difference (and it seems to match the version being called from the 
normal command line anyway). 

Thanks for any pointers or direction. 

Sincerely,
Marc


-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/02916c27-5582-49c5-afcb-72f3fb426c7bn%40googlegroups.com.
from pyqtgraph.Qt import QtCore, QtWidgets
import pyqtgraph.opengl as gl
import numpy as np
import sys

app = QtWidgets.QApplication([])
w = gl.GLViewWidget()
w.show()
w.setCameraPosition(distance=15, azimuth=-90)

g = gl.GLGridItem()
w.addItem(g)

md = gl.MeshData.sphere(rows=20, cols=20, radius=1)

m1 = gl.GLMeshItem(
    meshdata=md,
    smooth=True,
    color=np.array([1, 0, 0, 1]),
    shader="shaded",
    glOptions="additive",
)

w.addItem(m1)


if __name__ == "__main__":

    if (sys.flags.interactive != 1) or not hasattr(QtCore, "PYQT_VERSION"):
        QtWidgets.QApplication.instance().exec_()

Reply via email to