Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why does glVertexAttribPointer/glDrawArrays crash here (only with certain drivers/GPUs)?
Forum Updated to NodeBB v4.3 + New Features

Why does glVertexAttribPointer/glDrawArrays crash here (only with certain drivers/GPUs)?

Scheduled Pinned Locked Moved General and Desktop
18 Posts 3 Posters 13.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    giordi
    wrote on last edited by
    #6

    mmmm not sure if it s a shader program , where do you send the data on gpu?

    anyway the problem might be that some driver are more forgiving then other maybe? I am working with qt and opengl on diferent hardware and did not have many problems.

    Coding is powaaaaa

    1 Reply Last reply
    0
    • W Offline
      W Offline
      w1th0utnam3
      wrote on last edited by
      #7

      I don't know if you can call this forgiving. Interpreting an offset as an absolute pointer (what the desktop Nvidia driver apparently does) seems like something completely different...

      Anyway this code still crashes which uses the same methods in the same order as the example in the documentation I referred to above:

      (m_program refers to my QOpenGLShaderProgram from the initialization in my first post)

      @void OpenGLWindow::render()
      {
      static const GLfloat colorBg[] = {1.0f, 0.0f, 0.0f, 1.0f};
      glClearBufferfv(GL_COLOR, 0, colorBg);

      static GLfloat const triangleVertices[] = {
          0.8f,  0.8f,  0.0f, 1.0f,
          0.8f, 0.0f, 0.0f, 1.0f,
          0.0f,  0.0f, 0.0f, 1.0f
      };
      
      
      static const int vertexLocation = m_program.attributeLocation("vertex");
      
      m_program.enableAttributeArray(vertexLocation);
      m_program.setAttributeArray(vertexLocation, triangleVertices, 4);
      
      glDrawArrays(GL_TRIANGLES, 0, 3);
      
      m_program.disableAttributeArray(vertexLocation);
      

      }@

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giordi
        wrote on last edited by
        #8

        mmmm what if you try :
        glDrawArrays(GL_TRIANGLES, 0, 1); ?

        Coding is powaaaaa

        1 Reply Last reply
        0
        • W Offline
          W Offline
          w1th0utnam3
          wrote on last edited by
          #9

          It still crashes. It doesn't even draw a point when I change to GL_POINTS as it crashes at the vertex fetching stage. Of course I can use setAtrributeValue in this simple case but then I can't pass vertex data for multiple vertices to the shader. The second alternative is using a buffer like you suggested but then I don't get why this setAttributeArray method exists if it doesn't work consistently. Again this code works on my desktop GPU without a problem but I just had the chance to try it on a workstation at my job which uses a Nvidia NVS300 card with a Quadra/NVS driver and it also crashes.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giordi
            wrote on last edited by
            #10

            mmmmm that s weird then all my guesses expired, try to do that with the buffer if it solve the problem if so we can assume is a qt problem and maybe you can flag it as a bug.
            If not then it might be something driver related?

            Coding is powaaaaa

            1 Reply Last reply
            0
            • W Offline
              W Offline
              w1th0utnam3
              wrote on last edited by
              #11

              Ok. I get why using the Qt SetAttributeArray method also crashes. I had a look in the source of the QOpenGLShaderProgram and it does nothing else than calling the glVertexAttribPointer OpenGL method I used in my first example.

              @void QOpenGLShaderProgram::setAttributeArray (int location, const GLfloat *values, int tupleSize, int stride)
              {
              Q_D(QOpenGLShaderProgram);
              Q_UNUSED(d);
              if (location != -1) {
              d->glfuncs->glVertexAttribPointer(location, tupleSize, GL_FLOAT, GL_FALSE, stride, values);
              }@

              So I guess either it is ok to use glVertexAttribPointer in this way and it's a driver bug or it is not ok to do this and Qt should drop these methods (or implement them using a buffer) and therefore it's a bug in Qt.
              Somebody with a bit more OpenGL experience should be able to answer this problem... Do you think I should open a bug ticket for Qt and let them decide on which side the problem is?

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giordi
                wrote on last edited by
                #12

                I was reading around of other people having trouble with intel grapichs and opengl. Do you have a discrete card on your laptop to switch on and see if keeps crasing ?

                Yes might be worth to flag it to the qt guys

                Coding is powaaaaa

                1 Reply Last reply
                0
                • W Offline
                  W Offline
                  w1th0utnam3
                  wrote on last edited by
                  #13

                  I was just able to test the code on a workstation at my job with a Nvidia (Quadro) NVS300 graphics card that of course uses a Qudrao driver instead of the GeForce driver and it also crashed. But I changed some things in the code between testing it at home and at the workstation to see whether it fixes the problem on my laptop. So I'll wait reporting this issue until I verified that it still works at home and I didn't mess up something else. (But this is highly unlikely because it's still nearly exactly the same code as the example in the Qt documentation shows)

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    giordi
                    wrote on last edited by
                    #14

                    Keep me posted man I am quite curious now tx

                    Coding is powaaaaa

                    1 Reply Last reply
                    0
                    • W Offline
                      W Offline
                      w1th0utnam3
                      wrote on last edited by
                      #15

                      I'll do so! Maybe the OpenGL glVertexAttribPointer method is really not intended to be used in this way (all the books just describe the pointer to be an offset inside of an user created buffer). So the programmers of Qt might just got it wrong like I did and never noticed because some drivers accept it...

                      1 Reply Last reply
                      0
                      • W Offline
                        W Offline
                        w1th0utnam3
                        wrote on last edited by
                        #16

                        It still works correctly on my home PC. I reported the problem here: https://bugreports.qt-project.org/browse/QTBUG-40150

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          jaggomiken
                          wrote on last edited by
                          #17

                          I got the same problem. I solved it by using this invocation ordering:
                          setAttributeArray(0,...);
                          enableAttributeArray(0);
                          glDrawArrays();
                          disableAttributeArray(0);

                          It worked. I do this for every object I draw.
                          Regards.

                          1 Reply Last reply
                          0
                          • J Offline
                            J Offline
                            jaggomiken
                            wrote on last edited by
                            #18

                            I got the same problem. I solved it by using this invocation ordering:
                            setAttributeArray(0,...);
                            enableAttributeArray(0);
                            glDrawArrays();
                            disableAttributeArray(0);

                            It worked. I do this for every object I draw.
                            Regards.

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved