Qt5 crash (GLSL try to get uniforms)



  • I need to get uniform names from ogl shaders(for simple editor project). I did not want to parse shaders by hands, so I writed some tricky code :) In Qt4 this code works just fine, but in Qt5 appears crash at ctx.create(). This crash deep in Qt Gui library, somewhere in QWindow...

    @
    QGLFormat fmt = QGLFormat::defaultFormat();
    fmt.setVersion(2, 0);
    fmt.setProfile(QGLFormat::CompatibilityProfile);
    QWidget temp;
    QGLContext ctx(fmt, &temp);

    if (ctx.create())
    {
    ctx.makeCurrent();
    QGLFunctions fncs(&ctx);
    QGLShaderProgram prg(&ctx);

    bool needToLink = false;
    QGLShader vs(QGLShader::Vertex, &ctx);
    if (!vertex.isEmpty() && (needToLink |= vs.compileSourceCode(vertex)))
    prg.addShader(&vs);

    QGLShader fs(QGLShader::Fragment, &ctx);
    if (!fragment.isEmpty() && (needToLink |= fs.compileSourceCode(fragment)))
    prg.addShader(&fs);

    if (!needToLink)
    return;

    Q_ASSERT(prg.link());

    const QGLContext *context = QGLContext::currentContext();

    GLint total = -1;
    fncs.glGetProgramiv( prg.programId(), GL_ACTIVE_UNIFORMS, &total );
    for(GLint i = 0; i < total; ++i)
    {
    GLsizei nameLen = -1;
    GLint num = -1;
    GLenum type = GL_ZERO;
    char name[100];
    fncs.glGetActiveUniform( prg.programId(), i, sizeof(name)-1,
    &nameLen, &num, &type, name );
    name[nameLen] = 0;

    uniforms << glsl_var_type(shaderParamType(type), name, num);
    

    }
    }@

    What you think about it? May be it is bug in library. Or it's my bug. Anyway, how can I get uniform names - may be exists more beautiful solutions for this task?



  • In the docs I don't see a constructor for QGLContext taking a pointer to a QWidget at all. Which Qt5 version are you using? Maybe it has been deprecated.

    Generally in recent Qt5 versions the QGL... family of classes has been superseded by QOpenGL... classes. Maybe you should give them a try. They are a bit harder to use right now, so you should probably stick to an example like this one: http://qt-project.org/doc/qt-5/qtgui-openglwindow-example.html



  • [quote author="Cmdr" date="1406813572"]In the docs I don't see a constructor for QGLContext taking a pointer to a QWidget at all. Which Qt5 version are you using? Maybe it has been deprecated.[/quote]

    this way using of QGLContext i found in sample - but it was long time ago

    from qgl.h of 4.8.6 and 5.3.1
    @
    class Q_OPENGL_EXPORT QGLContext
    {
    Q_DECLARE_PRIVATE(QGLContext)
    public:
    QGLContext(const QGLFormat& format, QPaintDevice device);*
    QGLContext(const QGLFormat& format);
    virtual ~QGLContext();
    .............
    .............
    @

    and this constructor does not marked as QT_DEPRECATED_SINCE

    [quote author="Cmdr" date="1406813572"]
    Generally in recent Qt5 versions the QGL... family of classes has been superseded by QOpenGL... classes. Maybe you should give them a try. They are a bit harder to use right now, so you should probably stick to an example like this one: http://qt-project.org/doc/qt-5/qtgui-openglwindow-example.html[/quote]

    Of course i will try this new classes, but i have many old sources with using of qgl.



  • Another thing that I noticed: AFAIK QWidgets without a parent are initally invisible. Depending on your platform it might be impossible to create an OpenGL context for an invisible window. So you might try to call temp.show() prior to context initialization.

    Mixing QGL and QOpenGL should be no problem btw.



  • [quote author="Cmdr" date="1406816772"]Another thing that I noticed: AFAIK QWidgets without a parent are initally invisible. Depending on your platform it might be impossible to create an OpenGL context for an invisible window. So you might try to call temp.show() prior to context initialization.
    [/quote]

    It works on 4.8.6 without show, and this code works on ~10 PCs with different hardware(Intel, nVidia, AMD) no problems. But on Qt5 this code causes crash on all machines. Problem in Qt5 it seems.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.