title: QGLShaderProgram will not compile any shader since upgrading to Qt5
body: <p>I am finding that QGLShaderProgram is consistently failing to compile any shader and providing no error log. Here are the symptoms:</p>
  
  <ul>
  <li>QGLShaderProgram reports that it failed to compile but produces an empty error log. If I try to bind the shader an exception is thrown.</li>
  <li><p>I can compile a shader using <code>glCompileShader</code> without problem. However, the first time I try to compile this way <em>after</em> QGLShaderProgram has failed, fails with this error log:</p>
  
  <p>ERROR: error(#270) Internal error: Wrong symbol table level<br>
  ERROR: 0:2: error(#232) Function declarations cannot occur inside of functions:<br>
  main<br>
  ERROR: error(#273) 2 compilation errors.  No code generated  </p>
  
  <p>Following that one failure, the next time I try to compile using <code>glCompileShader</code> works fine.</p></li>
  <li><p>The problem has arisen only since upgrading from Qt 4.8 to 5.2. Nothing else has changed on this machine.</p></li>
  <li>I have tested on two PCs, one with an ATI Radeon HD 5700, the other with an AMD FirePro V7900. The problem only appears on the Radeon PC.</li>
  </ul>
  
  <p>Here is my test code demonstrating the problem:</p>
  
  <p>main.cpp</p>
  
  <pre><code>#include &lt;QApplication&gt;
  #include "Test.h"
  
  int main(int argc, char* argv[])
  {
      QApplication* app = new QApplication(argc, argv);
      Drawer* drawer = new Drawer;
      return app-&gt;exec();
  }
  </code></pre>
  
  <p>Test.h</p>
  
  <pre><code>#pragma once
  #include &lt;qobject&gt;
  #include &lt;QTimer&gt;
  #include &lt;QWindow&gt;
  #include &lt;QOpenGLContext&gt;
  #include &lt;QOpenGLFunctions&gt;
  
  class Drawer : public QWindow, protected QOpenGLFunctions
  {
      Q_OBJECT;
  
  public:
      Drawer();
  
      QTimer* mTimer;
      QOpenGLContext* mContext;
      int frame;
  
  public Q_SLOTS:
      void draw();
  };
  </code></pre>
  
  <p>Test.cpp</p>
  
  <pre><code>#include "Test.h"
  #include &lt;QGLShaderProgram&gt;
  #include &lt;iostream&gt;
  #include &lt;ostream&gt;
  
  using namespace std;
  
  Drawer::Drawer()
      : mTimer(new QTimer)
      , mContext(new QOpenGLContext)
      , frame(0)
  {
      mContext-&gt;create();
      setSurfaceType(OpenGLSurface);
      mTimer-&gt;setInterval(40);
      connect(mTimer, SIGNAL(timeout()), this, SLOT(draw()));
      mTimer-&gt;start();
      show();
  }
  
  const char* vertex = "#version 110 \n void main() { gl_Position = gl_Vertex; }";
  const char* fragment = "#version 110 \n void main() { gl_FragColor = vec4(0.0,0.0,0.0,0.0); }";
  
  void Drawer::draw()
  {
      mContext-&gt;makeCurrent(this);
      if (frame==0) {
          initializeOpenGLFunctions();
      }
      // Compile using QGLShaderProgram. This always fails
      if (frame &lt; 5)
      {
          QGLShaderProgram* prog = new QGLShaderProgram;
          bool f = prog-&gt;addShaderFromSourceCode(QGLShader::Fragment, fragment);
          cout &lt;&lt; "fragment "&lt;&lt;f&lt;&lt;endl;
          bool v = prog-&gt;addShaderFromSourceCode(QGLShader::Vertex, vertex);
          cout &lt;&lt; "vertex "&lt;&lt;v&lt;&lt;endl;
          bool link = prog-&gt;link();
          cout &lt;&lt; "link "&lt;&lt;link&lt;&lt;endl;
      }
      // Manual compile using OpenGL direct. This works except for the first time it
      // follows the above block
      {
          GLuint prog = glCreateShader(GL_FRAGMENT_SHADER);
          glShaderSource(prog, 1, &amp;fragment, 0);
          glCompileShader(prog);
          GLint success = 0;
          glGetShaderiv(prog, GL_COMPILE_STATUS, &amp;success);
          GLint logSize = 0;
          glGetShaderiv(prog, GL_INFO_LOG_LENGTH, &amp;logSize);
          GLchar* log = new char[8192];
          glGetShaderInfoLog(prog, 8192, 0, log);
          cout &lt;&lt; "manual compile " &lt;&lt; success &lt;&lt; endl &lt;&lt; log &lt;&lt; endl;
          delete[] log;
      }
      glClearColor(1,1,0,1);
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      mContext-&gt;swapBuffers(this);
      frame++;
  }
  </code></pre>
  
  <p>Elsewhere, I have tested using QGLWidget, and on a project that uses GLEW instead of QOpenGLFunctions with exactly the same results.</p>
  
  <p>The version of Qt I'm linking against was built with the following configuration:</p>
  
  <pre><code>configure -developer-build -opensource -nomake examples -nomake tests -mp -opengl desktop -icu -confirm-license
  </code></pre>
  
  <p>Any suggestions? Or shall I just send this in as a bug report?</p>
  
  <h1>Update</h1>
  
  <p>In response to peppe's comments:</p>
  
  <blockquote>
    <p>1) What does QOpenGLDebugLogger says?</p>
  </blockquote>
  
  <p>The only thing I can get from QOpenGLDebugLogger is </p>
  
  <pre><code>QWindowsGLContext::getProcAddress: Unable to resolve 'glGetPointerv'
  </code></pre>
  
  <p>This is printed when I initialize it (and not as a debug event firing, but just to console). It happens even though <code>mContext-&gt;hasExtension(QByteArrayLiteral("GL_KHR_debug"))</code> returns true and I'm initializing it within the first frame's draw() function.</p>
  
  <blockquote>
    <p>2) Can you print the compile log of the QOGLShaders even if they compile successfully? </p>
  </blockquote>
  
  <p>I cannot successfully compile QOpenGLShader or QGLShader at any point so I'm not able to test this. However, when compiling successfully using plain GL functions, the log returns blank.</p>
  
  <blockquote>
    <p>3) Which GL version did you get from the context? (Check with QSurfaceFormat).</p>
  </blockquote>
  
  <p>I've tried with versions 3.0, 3.2, 4.2, all with the same result.</p>
  
  <blockquote>
    <p>4) Please set the same QSurfaceFormat on both the context and the window before creating them
    5) Remember to create() the window</p>
  </blockquote>
  
  <p>I've implemented both of these now and the result is the same.</p>
  
  <p>I've just tested on a third PC and that has no issues. So it is this specific computer which, incidentally, happens to be a Mac Pro running Windows in bootcamp. It has had absolutely no trouble in any other context running the latest ATI drivers but I can only really conclude that there is a bug somewhere between the ATI drivers, this computer's graphics chip and QOpenGLShaderProgram.</p>
  
  <p>I think I'm unlikely to find a solution, so giving up. Thank you for all your input!</p>