2 Replies Latest reply on Oct 12, 2017 3:09 AM by sarimisar

    Windows handles leak with OpenGL (Radeon RX 460)

    sarimisar

      Hello,

      I'm experiencing a strange behavior with OpenGL (4.3, with compatibility profile for GL_QUADS ) on an AMD Radeon RX 460 (verify on driver 17.5.2 and 17.7.2).

      For some reasons I need to allocate and deallocate some VBO for each frame (because I need to render some dynamic geometries). In order to do that I use a code like that:

       

      // Class members

      GLuint m_VAO; // = 0

      GLuint m_VBO; // = 0

      bool m_bNotAllocated; // = true

      ...

      ...

      // Class function implementation called each frame

      void PaintGL()

      {

      ...

      ...

      if (m_bNotAllocated)

      {

           glGenVertexArrays(1, &m_VAO);

           glGenBuffers(1, &m_VBO );

       

           glBindVertexArray(m_VAO);

           glBindBuffer(GL_ARRAY_BUFFER, m_VBO);

           glBufferData(GL_ARRAY_BUFFER, numberOfVertices * 3 * sizeof(float), &vertices[0], GL_DYNAMIC_DRAW);

           glEnableVertexAttribArray(0);

           glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);

           glBindVertexArray(0);

       

           m_bNotAllocated = false;

      }

      else

      {

           glBindBuffer(GL_ARRAY_BUFFER, m_VBO);

           glBufferData(GL_ARRAY_BUFFER, numberOfVertices * 3 * sizeof(float), &vertices[0], GL_DYNAMIC_DRAW);

      }

      ...

      ...

      }

       

      My OpenGL context resides on a secondary thread and the rendering is offline (on texture). The main thread (the main thread of my MFC application) received a copy of the frame unloaded from GPU memory (by the OpenGL context thread) using glGetTexImage in order to render it on an MFC window.

      With the code below there is an important handles leak (~50 handles per seconds, with a famerate of ~30 fps). I know that glBufferData destroy the array buffer each time but the low performance is not a problem for me.

      It's important to note that my application works fine on an NVidia GTX 1060.

       

      The only way to fix the problem is allocate a big array buffer using glBufferData (sufficient to hold the geometry data in the worst case) and use glBufferSubData to update it.