Bug? Importing WGL crashes glReadPixel call with "wrong argument type" exception
Anton Ovsyannikov <[email protected]> Sat, 2 Sep 2017 22:31:29 +0300
| Newsgroups | gmane.comp.python.opengl.user |
|---|---|
| Message-ID | <CAEpUFHKbudfVze-10+KrO6LxEP6jyw5uG8dhF8BiJ=-qnEpT8w@mail.gmail.com> |
--===============1511897370615059304==
Content-Type: multipart/alternative; boundary="001a113794289aeb15055839ecff"
--001a113794289aeb15055839ecff
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Hello.
I am trying to use PyOpengGL for off-screen rendering, so I need WGL to
create gl context and then glReadPixels to retrieve data
First I wrote simple app with GLUT, but right after I import OpenGL.WGL
(just import, no more), the glReadPixels starts to crash with
ctypes.ArgumentError: argument 7: <type 'exceptions.TypeError'>: wrong type
The app, OpenGL version and stack trace are below. Now some of my
investigations
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
The crash starts in \OpenGL\GL\images.py line 369
GL_1_1.glReadPixels(
x,y,width,height,
format,type,
imageData
)
imageData in both cases is completely the same
The only difference in further workflow happens in
\OpenGL\platform\baseplatform.py line 125
def finalArgType( self, typ ):
"""Retrieve a final type for arg-type"""
if typ =3D=3D ctypes.POINTER( None ) and not getattr( typ, 'final',Fals=
e):
from OpenGL.arrays import ArrayDatatype
return ArrayDatatype
else:
return typ
With no WGL the 7th argument (while typ is <class 'ctypes.c_void_p'>) have
no "final" attribute set, so final type becomes ArrayDatatype and
everything works fine
But if to import WGL "final" flag is set, so <class 'ctypes.c_void_p'>
returned leading to "wrong type" exception in GL_1_1.glReadPixels call
I searched for "final" in WGL and found the following in
\OpenGL\raw\WGL\_types.py line 72
HANDLE =3D POINTER(None) # /home/mcfletch/pylive/OpenGL-ctypes/src/wgl.h:60
# TODO: figure out how to make the handle not appear as a void_p within the
code...
HANDLE.final =3D True
So we found who set up "final" flag for <class 'ctypes.c_void_p'>
But then I stuck up completely, have no single idea how to solve this type
conflict, suppose it's some issue in design
Have any idea how to solve it?
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
PyOpenGL package is
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl
PyOpenGL=E2=80=913.1.1=E2=80=91cp27=E2=80=91cp27m=E2=80=91win_amd64.whl
OpenGL.__version__
3.1.1
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
The App
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
# -*- coding: utf-8 -*-
# Just uncomment following line to reproduce the bug!
#import OpenGL.WGL
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
from PIL import Image
import sys
width, height =3D 300, 300
def init():
glClearColor(0.5, 0.5, 0.5, 1.0)
glColor(0.0, 1.0, 0.0)
gluOrtho2D(-1.0, 1.0, -1.0, 1.0)
glViewport(0, 0, width, height)
def render():
glClear(GL_COLOR_BUFFER_BIT)
glBegin(GL_LINES)
glVertex2d(-0.5, -0.5)
glVertex2d(0.5, 0.5)
glEnd()
glFlush()
def draw():
render()
glutSwapBuffers()
def main():
glutInit(sys.argv)
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
glutInitWindowSize(300, 300)
glutCreateWindow(b"OpenGL vs WGL")
init()
render()
glPixelStorei(GL_PACK_ALIGNMENT, 1)
data =3D glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE)
image =3D Image.frombytes("RGBA", (width, height), data)
image.save('output.png', 'PNG')
glutDisplayFunc(draw)
glutMainLoop()
main()
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
Stack trace with import WGL uncommented
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
Traceback (most recent call last):
File "C:/Users/Anton/Documents/Dev/PycharmProjects/OpenGL/OpenGLTest.py",
line 54, in <module>
main()
File "C:/Users/Anton/Documents/Dev/PycharmProjects/OpenGL/OpenGLTest.py",
line 47, in main
data =3D glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE)
File "C:\ProgramData\Anaconda2\lib\site-packages\OpenGL\GL\images.py",
line 372, in glReadPixels
imageData
File
"C:\ProgramData\Anaconda2\lib\site-packages\OpenGL\platform\baseplatform.py=
",
line 402, in __call__
return self( *args, **named )
ctypes.ArgumentError: argument 7: <type 'exceptions.TypeError'>: wrong type
--001a113794289aeb15055839ecff
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hello.<br><br>I am trying to use PyOpengGL for off-screen =
rendering, so I need WGL to create gl context and then glReadPixels to retr=
ieve data<br><br>First I wrote simple app with GLUT, but right after I impo=
rt OpenGL.WGL (just import, no more), the glReadPixels starts to crash with=
<br><br>ctypes.ArgumentError: argument 7: <type 'exceptions.TypeErro=
r'>: wrong type<br><br>The app, OpenGL version and stack trace are b=
elow. Now some of my investigations<br><br>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>The crash s=
tarts in \OpenGL\GL\images.py line 369<br><br>GL_1_1.glReadPixels(<br>=C2=
=A0 =C2=A0 x,y,width,height,<br>=C2=A0 =C2=A0 format,type,<br>=C2=A0 =C2=A0=
imageData<br>)<br><br>imageData in both cases is completely the same<br><b=
r>The only difference in further workflow happens in \OpenGL\platform\basep=
latform.py line 125<br><br>def finalArgType( self, typ ):<br>=C2=A0 =C2=A0 =
"""Retrieve a final type for arg-type"""<br>=
=C2=A0 =C2=A0 if typ =3D=3D ctypes.POINTER( None ) and not getattr( typ, &#=
39;final',False):<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 from OpenGL.arrays imp=
ort ArrayDatatype<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return ArrayDatatype<br>=
=C2=A0 =C2=A0 else:<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return typ<br><br>With n=
o WGL the 7th argument (while typ is <class 'ctypes.c_void_p'>=
;) have no "final" attribute set, so final type becomes ArrayData=
type and everything works fine<br><br>But if to import WGL "final"=
; flag is set, so <class 'ctypes.c_void_p'> returned leading =
to "wrong type" exception in GL_1_1.glReadPixels call<br><br>I se=
arched for "final" in WGL and found the following in \OpenGL\raw\=
WGL\_types.py line 72<br><br>HANDLE =3D POINTER(None) # /home/mcfletch/pyli=
ve/OpenGL-ctypes/src/wgl.h:60<br># TODO: figure out how to make the handle =
not appear as a void_p within the code...<br>HANDLE.final =3D True<br><br>S=
o we found who set up "final" flag for <class 'ctypes.c_vo=
id_p'><br><br>But then I stuck up completely, have no single idea ho=
w to solve this type conflict, suppose it's some issue in design<br><br=
>Have any idea how to solve it?<br><br><br>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>PyOpenGL pa=
ckage is<br><a href=3D"http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl"=
>http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl</a><br>PyOpenGL=E2=80=
=913.1.1=E2=80=91cp27=E2=80=91cp27m=E2=80=91win_amd64.whl<br><br>OpenGL.__v=
ersion__<br>3.1.1<br>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br><br>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>The App<br>=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D<br># -*- coding: utf-8 -*-<br><br># Just uncomment followin=
g line to reproduce the bug!<br>#import OpenGL.WGL<br><br>from OpenGL.GL im=
port *<br>from OpenGL.GLU import *<br>from OpenGL.GLUT import *<br><br>from=
PIL import Image<br>import sys<br><br>width, height =3D 300, 300<br><br>de=
f init():<br>=C2=A0 =C2=A0 glClearColor(0.5, 0.5, 0.5, 1.0)<br>=C2=A0 =C2=
=A0 glColor(0.0, 1.0, 0.0)<br>=C2=A0 =C2=A0 gluOrtho2D(-1.0, 1.0, -1.0, 1.0=
)<br>=C2=A0 =C2=A0 glViewport(0, 0, width, height)<br><br>def render():<br>=
<br>=C2=A0 =C2=A0 glClear(GL_COLOR_BUFFER_BIT)<br><br>=C2=A0 =C2=A0 glBegin=
(GL_LINES)<br>=C2=A0 =C2=A0 glVertex2d(-0.5, -0.5)<br>=C2=A0 =C2=A0 glVerte=
x2d(0.5, 0.5)<br>=C2=A0 =C2=A0 glEnd()<br><br>=C2=A0 =C2=A0 glFlush()<br><b=
r>def draw():<br>=C2=A0 =C2=A0 render()<br>=C2=A0 =C2=A0 glutSwapBuffers()<=
br><br>def main():<br>=C2=A0 =C2=A0 glutInit(sys.argv)<br><br>=C2=A0 =C2=A0=
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)<br>=C2=A0 =C2=A0 glutInitWindo=
wSize(300, 300)<br>=C2=A0 =C2=A0 glutCreateWindow(b"OpenGL vs WGL"=
;)<br><br>=C2=A0 =C2=A0 init()<br>=C2=A0 =C2=A0 render()<br><br>=C2=A0 =C2=
=A0 glPixelStorei(GL_PACK_ALIGNMENT, 1)<br>=C2=A0 =C2=A0 data =3D glReadPix=
els(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE)<br>=C2=A0 =C2=A0 image =
=3D Image.frombytes("RGBA", (width, height), data)<br>=C2=A0 =C2=
=A0 image.save('output.png', 'PNG')<br><br>=C2=A0 =C2=A0 gl=
utDisplayFunc(draw)<br>=C2=A0 =C2=A0 glutMainLoop()<br><br>main()<br>=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D<br><br><br>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>Stack trace with import WGL uncomme=
nted<br>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D<br><br>Traceback (most recent call last):<br>=C2=
=A0 File "C:/Users/Anton/Documents/Dev/PycharmProjects/OpenGL/OpenGLTe=
st.py", line 54, in <module><br>=C2=A0 =C2=A0 main()<br>=C2=A0 F=
ile "C:/Users/Anton/Documents/Dev/PycharmProjects/OpenGL/OpenGLTest.py=
", line 47, in main<br>=C2=A0 =C2=A0 data =3D glReadPixels(0, 0, width=
, height, GL_RGBA, GL_UNSIGNED_BYTE)<br>=C2=A0 File "C:\ProgramData\An=
aconda2\lib\site-packages\OpenGL\GL\images.py", line 372, in glReadPix=
els<br>=C2=A0 =C2=A0 imageData<br>=C2=A0 File "C:\ProgramData\Anaconda=
2\lib\site-packages\OpenGL\platform\baseplatform.py", line 402, in __c=
all__<br>=C2=A0 =C2=A0 return self( *args, **named )<br>ctypes.ArgumentErro=
r: argument 7: <type 'exceptions.TypeError'>: wrong type<br><=
/div>
--001a113794289aeb15055839ecff--
--===============1511897370615059304==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
--===============1511897370615059304==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
PyOpenGL Homepage
http://pyopengl.sourceforge.net
_______________________________________________
PyOpenGL-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyopengl-users
--===============1511897370615059304==--