Qt5 and the Vesta engine



  • I've been trying to debug a project that was ported from qt4 to qt5 over a year ago. It seems the original author of this project uses a Mac so I'm assuming that he didn't have the problem I'm about to state.

    On searching the projects home page, others had the same issue which was reported last April with Windows. It was also recently reported on Linux systems. At start up the program throws an exception with windows for a write access violation. With Linux it is a segmentation fault.

    I'm running windows 7 and tried 4 different qt5 versions. With qt5.0.1, it won't build because some features haven't been implemented. But I get the same run time error with qt5.2.0, qt5.3.2 and qt5.4.0.

    As near as I can tell, the program throws the exception after trying to execute the next line of code after a call to glTexImage3D. @ glTexImage3D(GL_TEXTURE_3D,
    0,
    GL_RGBA16F,
    m_scatterSunAngleSamples, m_scatterViewAngleSamples, m_scatterHeightSamples,
    0,
    GL_RGBA, GL_FLOAT,
    &m_inscatterTable[0]);
    @
    I've moved this code around and commented out lines of code below it but it crashes on the next line.
    If I comment out the code above, the program starts without any problems.

    The flow before this line tries to execute uses QByteArray to set up the variables that reads a file with 32 bit unsigned integers. It then assembles these integers into a Vector4f. It then does this: @#ifndef VESTA_OGLES2
    GLuint scatterTexId = 0;
    glGenTextures(1, &scatterTexId);
    glBindTexture(GL_TEXTURE_3D, scatterTexId);

    // Clamp scatter table values before converting them to half-floats. On at least one driver,
    // the conversion from 32-bit float to 16-bit half float seems to be performed incorrectly for
    // values very near zero.
    unsigned int tableSize = m_scatterSunAngleSamples * m_scatterViewAngleSamples * m_scatterHeightSamples;
    for (unsigned int i = 0; i < tableSize; ++i)
    {
        m_inscatterTable[i] = Vector4f(max(0.00001f, min(256.0f, m_inscatterTable[i].x())),
                                       max(0.00001f, min(256.0f, m_inscatterTable[i].y())),
                                       max(0.00001f, min(256.0f, m_inscatterTable[i].z())),
                                       max(0.00001f, min(256.0f, m_inscatterTable[i].w())));
    }
    
    glTexImage3D(GL_TEXTURE_3D,
                 0,
                 GL_RGBA16F,
                 m_scatterSunAngleSamples, m_scatterViewAngleSamples, m_scatterHeightSamples,
                 0,
                 GL_RGBA, GL_FLOAT,
                 &m_inscatterTable[0]);
    
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    //glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    m_scatterTexture = new TextureMap(scatterTexId, TextureProperties(TextureProperties::Clamp));
    
    glBindTexture(GL_TEXTURE_3D, 0);
    

    @
    Trying to execute that code the program throws an exception here: @ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);@

    I tried many things but one thing I tried was inserting this code. @ glewInit(); // For 3D texture support
    if(GL_TRUE != glewGetExtension("GL_EXT_texture3D"))
    {
    VESTA_LOG( "3D texture is not supported !" );
    return;
    }
    @

    This allows the program to exit and to go on running after reporting in the log that "3D texture is not supported" is not supported. All this code has been unchanged in the qt4 to qt5 port. And it does run fine in qt4.
    cartrite



  • I've since changed the debugger from sdk7.1 to sdk 8. I started seeing debug info that made sense immediately. I'm seeing something that looks like it may be causing a problem that is generated from these 6 lines of code.
    @ GLuint texId = 0;
    glGenTextures(1, &texId);
    glBindTexture(GL_TEXTURE_2D, texId);
    .
    .
    .
    GLuint scatterTexId = 0;
    glGenTextures(1, &scatterTexId);
    glBindTexture(GL_TEXTURE_3D, scatterTexId);
    @

    When I put break points in and look at the values for texId and scatterTexId they show 0 for the version built with qt5. But with the version built with qt4, they increment starting from 8.

    Basically, a 2d and a 3d texture is drawn on 3 planetary bodies in this solar system. Earth, Mars and Titan. 6 textures. I put break points with the debugger. With the qt4 version, the first break point shows a value of 8 for the 2d texture. 9 for the 3d texture. 10 for the second 2d texture and so on til the last texture which is 13.

    With the qt5 version, the value at the first break point is zero. The value at the second break point is also zero. This is the value for the 3d texture. Then it crashes after the 3dtexture.

    Maybe it's glBindTexture or glGenTextures that is not working right?
    cartrite



  • I found what I think is a fix. GL was not being initialized before trying to generate textures. It was the 3d ones that caused the crash though. I found that inserting this code into the help menu which is initialized at start up, it stops it from crashing and actually allows the code posted above to work correctly. @ QMessageBox glInfo(this);
    glInfo.setText("This is a temporary fix.<br>\nClose to continue");
    glInfo.exec();

    @
    I actually started this thread here looking for help but maybe it will help someone else in the future.
    cartrite



  • Using QMessageBox or QDialog were the only ways so far that initialized GL. The other ways I tried, GlewInit ,creating a context, or setting the GL version fail to Initialize GL. The Vesta engine is what needs to use GL at start up to generated precomputed atmosphere textures. I tried to initialize GL before it gets there.

    Anyhow, a couple of questions. What are the messagebox and qdialog doing to initialize GL? And can I do the same thing transparently?
    cartrite


Log in to reply
 

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