[SOLVED] question on initializeOpenGLFunctions returning false

Issue

I’m running into the following segfault after initializeGL() fails. Any ideas as to what might cause this? There is no problem when I inherit from QOpenGLFunctions but I need v3.0 functionality.

class MyGLWidget : public QOpenGLWidget, protected QOpenGLFunctions
QOpenGLFunctions_3_3_Compatibility::glClearColor (this=0x5d3c40, red=0, green=0, blue=0, alpha=1) at /usr/include/qt5/QtGui/qopenglfunctions_3_3_compatibility.h:1064
1064        d_1_0_Core->f.ClearColor(red, green, blue, alpha);
class MyGLWidget : public QOpenGLWidget, protected QOpenGLFunctions_3_3_Compatibility
{
    Q_OBJECT
...
};

    void initializeGL() override {
        makeCurrent();
        bool ret =  initializeOpenGLFunctions();
        std::cout << std::boolalpha << ret << std::endl; // FALSE
        glClearColor(0, 0, 0, 1); // CRASH
    }

Solution

I solved this problem as follows. I inherited from QOpenGLFunctions and then used the corresponding Core profile 3.3 in my case when needed.

class MyGLWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
   Q_OBJECT
...
protected:
   void initializeGL() override {
        initializeOpenGLFunctions();
        auto * glFunctions = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_3_3_Core>();
        glFunctions->glClearColor(0, 0, 0, 1);
    }
};

Answered By – user3882729

Answer Checked By – Katrina (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *