Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python PyOpenGL glReadPixels在最终指针创建后导致ctypes参数错误_Python_Python Import_Importerror_Pyopengl_Opengl Extensions - Fatal编程技术网

Python PyOpenGL glReadPixels在最终指针创建后导致ctypes参数错误

Python PyOpenGL glReadPixels在最终指针创建后导致ctypes参数错误,python,python-import,importerror,pyopengl,opengl-extensions,Python,Python Import,Importerror,Pyopengl,Opengl Extensions,我对pyopengl及其导入有一个奇怪的问题,下面是一个从一个大得多的程序中裁剪出来的小测试程序,但它足以说明这个问题。您需要安装PyOpenGL,如果您按原样运行它,它会显示一个空白窗口,如果您单击并拖动它,它会打印出一些0。如果取消注释下面的行HANDLE.final=True,那么它将停止工作,请参阅下面的回溯 from OpenGL.GL import * from OpenGL.GLUT import * from ctypes import POINTER import sys H

我对pyopengl及其导入有一个奇怪的问题,下面是一个从一个大得多的程序中裁剪出来的小测试程序,但它足以说明这个问题。您需要安装PyOpenGL,如果您按原样运行它,它会显示一个空白窗口,如果您单击并拖动它,它会打印出一些0。如果取消注释下面的行
HANDLE.final=True
,那么它将停止工作,请参阅下面的回溯

from OpenGL.GL import *
from OpenGL.GLUT import *
from ctypes import POINTER
import sys

HANDLE = POINTER(None)
#HANDLE.final = True

def display():
    glutSwapBuffers()

glutInit(sys.argv)
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
glutInitWindowSize(400,400)
glutCreateWindow("GLUT Window")

glutDisplayFunc(display)

def readPx(x,y):
    data_all = glReadPixels(x, y, 1, 1, GL_RGB, GL_BYTE)
    print data_all

glutMotionFunc(readPx)

glutMainLoop()
未注释该行时,它会执行以下操作:

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\OpenGL\GLUT\special.py", line 130, in safeCall
    return function( *args, **named )
  File "C:\Users\Robin\dev\ogl_bug\ogl_bug.py", line 19, in readPx
    data_all = glReadPixels(x, y, 1, 1, GL_RGB, GL_BYTE)
  File "C:\Python27\lib\site-packages\OpenGL\GL\images.py", line 371, in glReadPixels
    imageData
  File "C:\Python27\lib\site-packages\OpenGL\platform\baseplatform.py", line 402, in __call__
    return self( *args, **named )
ArgumentError: argument 7: <type 'exceptions.TypeError'>: wrong type
GLUT Motion callback <function readPx at 0x02CC5830> with (238, 190),{} failed: returning None argument 7: <type 'exceptions.TypeError'>: wrong type
回溯(最近一次呼叫最后一次):
文件“C:\Python27\lib\site packages\OpenGL\GLUT\special.py”,第130行,在safeCall中
返回函数(*args,**已命名)
文件“C:\Users\Robin\dev\ogl\u bug\ogl\u bug.py”,第19行,在readPx中
data_all=glReadPixels(x,y,1,1,GL_RGB,GL_字节)
文件“C:\Python27\lib\site packages\OpenGL\GL\images.py”,第371行,以glReadPixels为单位
图像数据
文件“C:\Python27\lib\site packages\OpenGL\platform\baseplatform.py”,第402行,在调用中__
返回self(*args,**已命名)
ArgumentError:参数7::类型错误
带有(238190),{}的GLUT运动回调失败:返回None参数7::类型错误
在我的大型程序中,当尝试导入OpenGL.raw.WGL.\u类型时,该句柄代码被掩埋了5或6个导入深度,该类型由任何WGL OpenGL扩展导入,但这是仍然导致错误的最小片段


我不明白为什么这行的出现会对一个看似无关的gl调用产生影响-我如何使用load this扩展而不破坏PyOpenGL的其他部分?

我找到了原因-
指针(无)
返回
ctypes.c\u void\p
,这是一个单例,这意味着导入后,
.final
属性可以很容易地看到,这可能会打乱某些类型检查机制

它在github版本的PyopenGL中得到了修复。这是提交:

通过在任何OpenGL扩展之前导入此小模块,可以在当前版本的PyOpenGL中修复此问题:

import OpenGL.raw.WGL._types as t
from ctypes import _SimpleCData, _check_size

delattr(t.HANDLE, "final")

class HANDLE(_SimpleCData):
    _type_ = "P"

_check_size(HANDLE)

HANDLE.final = True

t.HANDLE = HANDLE
t.HGLRC = HANDLE
t.HDC = HANDLE

t.HPBUFFERARB = HANDLE
t.HPBUFFEREXT = HANDLE
这将导入导致问题的PyOpenGL模块,修复对
c\u void\u p
的损坏,然后从上面的github链接将
句柄
变量及其别名重新分配给
\u SimpleData
解决方案