Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt + OpenGL + Graphics View Framework, crash with access 0x00000000



  • I create a new Qt application with OpenGL,just add scene in like this:

    @{
    ui->setupUi(this);

    QGraphicsView *pSceneView = new QGraphicsView(this);
    setCentralWidget(pSceneView);
    QGLWidget *pGLWidget = new QGLWidget;
    pSceneView->setViewport(pGLWidget);
    pSceneView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    pSceneView->setScene(new MainScene);
    pGLWidget->makeCurrent();

    QGLFunctions *glFuncs = new QGLFunctions(pGLWidget->context());
    GLuint i;
    glFuncs->glGenBuffers(1, &i);
    glFuncs->glBindBuffer(GL_ARRAY_BUFFER, i); // unbind buffer cause crash
    }@

    the class MainScene is inherit from QGraphicsScene, just set SceneRect and rewrite drawBackground like this:
    @MainScene::MainScene(QObject parent / = 0 */)
    :QGraphicsScene(parent)
    {
    setSceneRect(-1024/2, -768/2, 1024, 768);
    }

    void MainScene::drawBackground(QPainter *painter, const QRectF &rect)
    {
    painter->drawRect(sceneRect());
    }@

    if i don't rewrite drawBackground or don't call glBindBuffer, it didn't crash。the Qt version is 5.3.2, os is windows 7。


Log in to reply