【发布时间】:2017-03-28 06:47:08
【问题描述】:
我正在清理一些曾经运行但不再运行的 wxPython/PyOpenGL 代码——显然它在一个或另一个模块中进行了一些更新后停止工作,我不知道什么时候。
这是一个重现错误的小示例应用程序。
import wx
from wx import glcanvas
from OpenGL.GLUT import *
from OpenGL.GL import *
class WxMyTestApp(wx.App):
def __init__(self):
wx.App.__init__(self)
def OnInit(self):
self.viewFrame = wx.Frame(None, -1, 'viewFrame', wx.DefaultPosition, (400,400))
self.canvas = glcanvas.GLCanvas(self.viewFrame)
self.canvas.Bind(wx.EVT_PAINT, self.OnPaint)
return True
def OnPaint(self, ev):
print "OnPaint ",
dc = wx.PaintDC(self.canvas)
self.canvas.SetCurrent()
self.redraw(ev)
def redraw(self, ignoredEvent):
glPushMatrix()
glColor3f(1.0, 1.0, 0.0)
glLineWidth(1)
glutWireSphere(0.5, 10,10)
glPopMatrix()
glFlush()
self.canvas.SwapBuffers()
if __name__ == '__main__':
d = WxMyTestApp()
d.viewFrame.Show()
d.MainLoop()
(注意我使用的是 wx.App 而不是 wx.PySimpleApp,因为我的真实代码使用了多个窗口。)运行测试代码,框架在左上角显示一个小的白色矩形,并且在调整大小时给出这个重复的错误:
Traceback (most recent call last):
File "myTestApp.py", line 18, in OnPaint
self.redraw(ev)
File "myTestApp.py", line 20, in redraw
glPushMatrix()
File "C:\users\user\appdata\local\enthought\canopy\user\lib\site-packages\OpenGL\platform\baseplatform.py", line 402, in __call__
return self( *args, **named )
File "C:\users\user\appdata\local\enthought\canopy\user\lib\site-packages\OpenGL\error.py", line 232, in glCheckError
baseOperation = baseOperation,
OpenGL.error.GLError: GLError(
err = 1282,
description = 'invalid operation',
baseOperation = glPushMatrix,
cArguments = ()
在这里推送真的有问题吗?我怀疑这个问题与 GL 设备上下文有关,但不知道如何调试它。 Python 2.7.10、wxPython 3.0.2.0-3、PyOpenGL 3.1.0-2(Canopy 分布)。
【问题讨论】: