getActiveAttrib name_offset equals or exceeds array length

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

getActiveAttrib name_offset equals or exceeds array length

Stephen Ranger
I am trying to get the currently available list of shader attributes and have created my program, linked it, and then queried GL_ACTIVE_ATTRIBUTES (3) and GL_ACTIVE_ATTRIBUTE_MAX_LENGTH (0). So, I supposedly have three attributes but their names have a zero length. Then, once I try to query using glGetActiveAttrib, I get a GLException: array offset argument "name_offset" (0) equals or exceeds array length (0). Before this step, I am successfully checking glGetActiveUniform so I believe everything is created and linked successfully. I don't understand how I can have > 0 active attributes but all of their names have a length == 0.

Here's a trace gl for my shader activation step up until the exception

glCreateProgram() = 1
glCreateShader(<int> 0x8B31) = 2
glShaderSource(<int> 0x2, <int> 0x1, <[Ljava.lang.String;>, <[I>, <int> 0x0)
glCompileShader(<int> 0x2)
glGetShaderiv(<int> 0x2, <int> 0x8B84, <java.nio.IntBuffer> java.nio.DirectIntBufferU[pos=0 lim=1 cap=1])
glGetShaderiv(<int> 0x2, <int> 0x8B81, <[I>, <int> 0x0)
glAttachShader(<int> 0x1, <int> 0x2)
glDeleteShader(<int> 0x2)
glCreateShader(<int> 0x8B31) = 3
glShaderSource(<int> 0x3, <int> 0x1, <[Ljava.lang.String;>, <[I>, <int> 0x0)
glCompileShader(<int> 0x3)
glGetShaderiv(<int> 0x3, <int> 0x8B84, <java.nio.IntBuffer> java.nio.DirectIntBufferU[pos=0 lim=1 cap=1])
glGetShaderiv(<int> 0x3, <int> 0x8B81, <[I>, <int> 0x0)
glAttachShader(<int> 0x1, <int> 0x3)
glDeleteShader(<int> 0x3)
glCreateShader(<int> 0x8B30) = 4
glShaderSource(<int> 0x4, <int> 0x1, <[Ljava.lang.String;>, <[I>, <int> 0x0)
glCompileShader(<int> 0x4)
glGetShaderiv(<int> 0x4, <int> 0x8B84, <java.nio.IntBuffer> java.nio.DirectIntBufferU[pos=0 lim=1 cap=1])
glGetShaderiv(<int> 0x4, <int> 0x8B81, <[I>, <int> 0x0)
glAttachShader(<int> 0x1, <int> 0x4)
glDeleteShader(<int> 0x4)
glLinkProgram(<int> 0x1)
glGetProgramiv(<int> 0x1, <int> 0x8B82, <[I>, <int> 0x0)
glGetProgramiv(<int> 0x1, <int> 0x8B84, <java.nio.IntBuffer> java.nio.DirectIntBufferU[pos=0 lim=1 cap=1])
glGetProgramiv(<int> 0x1, <int> 0x8B86, <[I>, <int> 0x0)
glGetProgramiv(<int> 0x1, <int> 0x8B87, <[I>, <int> 0x0)
glGetActiveUniform(<int> 0x1, <int> 0x0, <int> 0x26, <[I>, <int> 0x0, <[I>, <int> 0x0, <[I>, <int> 0x0, <[B>, <int> 0x0)
glGetUniformLocation(<int> 0x1, <java.lang.String> dataBuffer) = 0
glGetActiveUniform(<int> 0x1, <int> 0x1, <int> 0x26, <[I>, <int> 0x0, <[I>, <int> 0x0, <[I>, <int> 0x0, <[B>, <int> 0x0)
glGetUniformLocation(<int> 0x1, <java.lang.String> shininess) = 1
glGetActiveUniform(<int> 0x1, <int> 0x2, <int> 0x26, <[I>, <int> 0x0, <[I>, <int> 0x0, <[I>, <int> 0x0, <[B>, <int> 0x0)
glGetUniformLocation(<int> 0x1, <java.lang.String> gl_FrontLightModelProduct.sceneColor) = -1
glGetActiveUniform(<int> 0x1, <int> 0x3, <int> 0x26, <[I>, <int> 0x0, <[I>, <int> 0x0, <[I>, <int> 0x0, <[B>, <int> 0x0)
glGetUniformLocation(<int> 0x1, <java.lang.String> gl_LightSource[0].ambient) = -1
glGetActiveUniform(<int> 0x1, <int> 0x4, <int> 0x26, <[I>, <int> 0x0, <[I>, <int> 0x0, <[I>, <int> 0x0, <[B>, <int> 0x0)
glGetUniformLocation(<int> 0x1, <java.lang.String> gl_LightSource[0].constantAttenuation) = -1
glGetActiveUniform(<int> 0x1, <int> 0x5, <int> 0x26, <[I>, <int> 0x0, <[I>, <int> 0x0, <[I>, <int> 0x0, <[B>, <int> 0x0)
glGetUniformLocation(<int> 0x1, <java.lang.String> gl_LightSource[0].diffuse) = -1
glGetActiveUniform(<int> 0x1, <int> 0x6, <int> 0x26, <[I>, <int> 0x0, <[I>, <int> 0x0, <[I>, <int> 0x0, <[B>, <int> 0x0)
glGetUniformLocation(<int> 0x1, <java.lang.String> gl_LightSource[0].linearAttenuation) = -1
glGetActiveUniform(<int> 0x1, <int> 0x7, <int> 0x26, <[I>, <int> 0x0, <[I>, <int> 0x0, <[I>, <int> 0x0, <[B>, <int> 0x0)
glGetUniformLocation(<int> 0x1, <java.lang.String> gl_LightSource[0].position) = -1
glGetActiveUniform(<int> 0x1, <int> 0x8, <int> 0x26, <[I>, <int> 0x0, <[I>, <int> 0x0, <[I>, <int> 0x0, <[B>, <int> 0x0)
glGetUniformLocation(<int> 0x1, <java.lang.String> gl_LightSource[0].specular) = -1
glGetActiveUniform(<int> 0x1, <int> 0x9, <int> 0x26, <[I>, <int> 0x0, <[I>, <int> 0x0, <[I>, <int> 0x0, <[B>, <int> 0x0)
glGetUniformLocation(<int> 0x1, <java.lang.String> gl_ModelViewMatrix) = -1
glGetActiveUniform(<int> 0x1, <int> 0xA, <int> 0x26, <[I>, <int> 0x0, <[I>, <int> 0x0, <[I>, <int> 0x0, <[B>, <int> 0x0)
glGetUniformLocation(<int> 0x1, <java.lang.String> gl_ModelViewProjectionMatrix) = -1
glGetActiveUniform(<int> 0x1, <int> 0xB, <int> 0x26, <[I>, <int> 0x0, <[I>, <int> 0x0, <[I>, <int> 0x0, <[B>, <int> 0x0)
glGetUniformLocation(<int> 0x1, <java.lang.String> gl_NormalMatrix) = -1
glGetProgramiv(<int> 0x1, <int> 0x8B89, <[I>, <int> 0x0)
glGetProgramiv(<int> 0x1, <int> 0x8B8A, <[I>, <int> 0x0)
// Active Attributes: 3
// Max Attribute Name Length: 0
glGetActiveAttrib(<int> 0x1, <int> 0x0, <int> 0x0, <[I>, <int> 0x0, <[I>, <int> 0x0, <[I>, <int> 0x0, <[B>, <int> 0x0)

javax.media.opengl.GLException: array offset argument "name_offset" (0) equals or exceeds array length (0)
        at jogamp.opengl.gl4.GL4bcImpl.glGetActiveAttrib(GL4bcImpl.java:6536)
        at javax.media.opengl.TraceGL2.glGetActiveAttrib(TraceGL2.java:6103)
Reply | Threaded
Open this post in threaded view
|

Re: getActiveAttrib name_offset equals or exceeds array length

sranger
Another note; it also only seems to happen on our GeForce 590 and Quadro 6000 systems; it doesn't happen on a Radeon 7970 or GeForce GTS 360M.


 - Stephen
Reply | Threaded
Open this post in threaded view
|

Re: getActiveAttrib name_offset equals or exceeds array length

sranger
In reply to this post by Stephen Ranger
So, I've created a C++ demo and ran it in Linux and Windows and on the 590/6000 systems it still has the same issue (sans GLException of course) and on the Radeon 7970 and GeForce 360M it works fine. So, it doesn't look like a JOGL issue and instead is probably an nvidia driver issue. So you can all safely ignore this as a JOGL bug I think. However, if it doesn't get fixed (unless I'm missing something that NEEDS to be done before querying attributes but it doesn't look like it) it still might be an issue for some people and should be pointed out.


 - Stephen
Reply | Threaded
Open this post in threaded view
|

Re: getActiveAttrib name_offset equals or exceeds array length

gouessej
Administrator
Please can you give some pointers about this probable driver bug?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: getActiveAttrib name_offset equals or exceeds array length

sranger
This post was updated on .
I'm using the 310.90 drivers (current version on nVidia's site) and as a temporary workaround, if the GL_ACTIVE_ATTRIBUTES value is greater than zero and the GL_ACTIVE_ATTRIBUTE_MAX_LENGTH value is equal to zero, I just use a large-enough value for the max length as it's only used to initialize a byte array for loading the names of the attributes and the actual attribute length is queried later anyway with glGetActiveAttrib.

However, if you'd like to reproduce this yourself, after linking your shader, do the following:

      final int[] iBuff = new int[1];

      /* Get number of uniforms */
      gl.glGetProgramiv(programId, GL2.GL_ACTIVE_ATTRIBUTES, iBuff, 0);
      final int activeAttributes = iBuff[0];

      /* Allocate buffer to store uniform names from OpenGL */
      // TODO: returns 0 on GeForce 590 and Quadro 6000 under linux and windows
      gl.glGetProgramiv(programId, GL2.GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, iBuff, 0);
      final int maxNameSize = iBuff[0];

      // temporary fix for nvidia bug
      // final int maxNameSize = (iBuff[0] == 0 && activeAttributes > 0) ? 2000 : iBuff[0];

      final byte[] nameBuffer = new byte[maxNameSize];

      /* Loop and get metadata for each */
      final int[] sizeBuffer = new int[1];
      final int[] typeBuffer = new int[1];
      final int[] nameLenBuffer = new int[1];
      for (int i = 0; i < activeAttributes; ++i) {
            // throws GLException on nVidia 590/Quadro 6000 hardware
            gl.glGetActiveAttrib(programId, i, maxNameSize, nameLenBuffer, 0, sizeBuffer, 0, typeBuffer, 0, nameBuffer, 0);
      }

I don't have access to nvidia's driver code so there's not much else I can do to verify it is indeed their issue but from the testing I've done under linux and windows with multiple graphics cards, it seems like a driver issue.

EDIT: they released new drivers today (314.07) and it still occurs. However, it only happens when the shader is only using the default built-in attributes (gl_Vertex, gl_Color, etc) and no custom attributes


 - Stephen