【问题标题】:glBufferData still crashesglBufferData 仍然崩溃
【发布时间】:2016-04-08 02:49:54
【问题描述】:

我正在尝试基于以下示例创建 Python OpenGL 代码: https://www.opengl.org/wiki/Tutorial2:_VAOs,_VBOs,_Vertex_and_Fragment_Shaders_(C_/_SDL)

我在调用 glBufferData 时遇到应用程序崩溃。

我面临的问题与这里提到的问题相同: Crash on glBufferDatahttp://www.cplusplus.com/forum/beginner/47978/

但是,这些页面中提到的解决方案仍然有效。我正在使用 PyQt5.5、Python 3.4.0 和 PyOpenGL 3.1。此外,GPU Caps Viewer 报告说我的机器上有 Open GL 4.5。

非常感谢任何帮助或指导。

注意:在崩溃时启动 PyDev 调试器时,检查

self.context().isValid()

返回真

初始化代码如下:

from PyQt5 import QtGui, QtCore
import sys, array
from OpenGL import GL

class PulleysWithWeights3D( QtGui.QOpenGLWindow ):

    def __init__(self):
        super().__init__()

        # These are the 4D coordinates of a triangle that needs to be drawn.
        _vertexPos = [ 0.075, 0.075, 0.075, 0.075, \
                      0.275, 0.275, 0.275, 0.075, \
                      0.550, 0.550, 0.550, 0.075 ]

        # These are the RGBA colours for each vertex.
        _vertexCols = [ 0.875, 0.525, 0.075, 0.500, \
                       0.875, 0.525, 0.075, 0.500, \
                       0.875, 0.525, 0.075, 0.500 ]

        self._deltaPositions = array.array( 'f', _vertexPos )
        self._deltaColours = array.array( 'f', _vertexCols )

        self._appSurfaceFormat = QtGui.QSurfaceFormat()

        self._appSurfaceFormat.setProfile( QtGui.QSurfaceFormat.CoreProfile )
        self._appSurfaceFormat.setMajorVersion( 4 )
        self._appSurfaceFormat.setMinorVersion( 2 )
        self._appSurfaceFormat.setRenderableType( QtGui.QSurfaceFormat.OpenGL )
        self._appSurfaceFormat.setSamples( 16 )          
        self._appSurfaceFormat.setSwapBehavior( QtGui.QSurfaceFormat.DoubleBuffer )
        self.setSurfaceType( QtGui.QSurface.OpenGLSurface )

        self.setFormat( self._appSurfaceFormat )

        self.setIcon( QtGui.QIcon('OpenGL.png') )
        self.setTitle( 'Pulleys3D' )
        self.setMinimumSize( QtCore.QSize( 1280, 640 ) )
        self.show()


    def initializeGL(self):

        GL.glClearColor( 0.0, 0.0, 0.0, 0.500 ) # RGBA
        GL.glClearDepthf(1.0)
        GL.glClearStencil(0)
        GL.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT )

        self._vaoColouredDelta = GL.glGenVertexArrays(1) 
        GL.glBindVertexArray( self._vaoColouredDelta )

        self._vboPositions = GL.glGenBuffers(1)
        GL.glBindBuffer( GL.GL_ARRAY_BUFFER, self._vboPositions )

        GL.glBufferData( GL.GL_ARRAY_BUFFER, \
                         self._deltaPositions.buffer_info()[1] * self._deltaPositions.itemsize, \
                         self._deltaPositions.tolist(), GL.GL_STATIC_DRAW )

        # PS: Code has been stopped here.

    def resizeGL(self, wd, ht ):
        GL.glViewport( 0, 0, wd, ht )


    def paintGL(self):
        pass


if __name__ == '__main__':
    _pww3dApp = QtGui.QGuiApplication( sys.argv )
    _pww3d = PulleysWithWeights3D()
    sys.exit( _pww3dApp.exec_() )

【问题讨论】:

  • 以下示例中的代码似乎使用了带有 3 个参数的 glBufferData,而 PyOpenGL 指定了 4.link。我正在尝试这个。
  • 在 glBufferData 之前是否有任何注册的 OpenGL 错误?
  • @Andreas 不,单步执行代码时,调试控制台中没有列出任何错误。
  • AFAIK opengl 错误不会自动抛出到调试控制台。您需要通过glGetErrors手动检索它们,并根据收到的代码进行解析。
  • 谢谢@Andreas - 这是新信息。我会试试这个。

标签: pyqt5 pyopengl


【解决方案1】:

问题已解决。对

的调用
self._deltaPositions.tolist()

导致问题。我把它换成了

self._deltaPositions.tostring()

然后崩溃就消失了。

【讨论】:

  • 现在使用 tobytes()
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-31
  • 2023-03-20
相关资源
最近更新 更多