title: Unexpected behavior of glGetActiveUniformName
body: <p>glGetActiveUniformName is a function that can be used to query a GLSL uniform's name length according to the <strong><a href="http://www.opengl.org/sdk/docs/man3/xhtml/glGetActiveUniformName.xml" rel="nofollow">documentation</a></strong>. This can be done by setting <em>uniformName</em> to NULL (0) and supplying an <em>GLsizei</em> pointer as out variable to <em>length</em>. When doing this one would expect the length of the uniform's name to be returned in the <em>length</em> parameter, but this variable is unchanged after calling the function as described above. An error is given which is GL_INVALID_VALUE which, according to the documentation, can mean one of three things:</p>
  
  <pre><code>GL_INVALID_VALUE is generated if uniformIndex is greater than or equal to the value of GL_ACTIVE_UNIFORMS.
  
  GL_INVALID_VALUE is generated if bufSize is negative.
  
  GL_INVALID_VALUE is generated if program is not the name of a program object for which glLinkProgram has been issued.
  </code></pre>
  
  <p>In my case the <em>uniformIndex</em> is 0 and GL_ACTIVE_UNIFORMS reports 5. <em>bufSize</em> is set to 0 on purpose and therefore can't be negative. Calling glGetProgram with GL_LINK_STATUS on the program used returns GL_TRUE (1). This rules out all 3 known causes of this error. There have been no previous errors according to glGetError just before the call to glGetActiveUniformName and calling it with a valid <em>bufSize</em> and <em>uniformName</em> both succeeds without error and writes to the buffer in <em>uniformName</em> as expected; correctly writing the uniform's name.</p>
  
  <p>Apart from not reporting the length of the uniform's name and erring instead, there are other troubling signs; if <em>bufSize</em> is set to a positive value greater than zero and <em>uniformName</em> is left NULL (0) the function writes to <em>uniformName</em> anyway, potentially causing serious memory corruption. This behavior is not according to the specification either which states that should <em>uniformName</em> be NULL (0) then nothing shall be written to it.</p>
  
  <p>Putting all the information above together I think I can safely conclude that there is no error in my code but instead there is an error somewhere outside of my own code which is why I am posting here. Is there anyone who can verify the behavior of this function when used as described above?</p>
  
  <p>I think this could well be a driver issue which means that only people running nVidia drivers/hardware would see the issue but it is too early to exclude any group of users. </p>
  
  <p>P.S.: The above occurred on a machine running the latest drivers (updated specifically to verify the above statements) with an nVidia GeForce 660 GTX installed. The machine is a Dell XPS 8500 running 64-bit Windows 7 Professional SP1. The program was built using Visual Studio 2012 Professional, fully updated. This post was also posted to the nVidia Developer Forums and DevMaster, posted here for better exposure and in the hopes of solving the issue faster.</p>
  
  <p>UPDATE 1: The code in question was tested on another machine with a different GPU (nVidia GeForce 9600M GT), again with the latest drivers and delivered identical results. This machine is running 64-bit Windows 7 Ultimate SP1. Again the binary was built with VS2012.</p>