# Why is glUniform1i() returning GL_INVALID_VALUE?

I have a sampler variable in a shader:

 uniform sampler2DArray tiles;


Which I am trying to bind to a texture unit in GL:

    int tilesUniformIndex = glGetUniformLocation(shaderProgramId,"tiles");
System.out.println("tiles: "+tilesUniformIndex);
glok();  // <- This calls glGetError() and throws exception if not-ok
glUniform1i(tilesUniformIndex, GL_TEXTURE0 + TILE_TEXTURE_UNIT_INDEX);
glok();


TILE_TEXTURE_UNIT_INDEX is a constant defined to be zero.

The location is being correctly introspected, output is:

 tiles: 7


which is the correct binding location I expect in context of the shader source.

The /second/ glok() is throwing an exception, with 0x501 GL_INVALID_VALUE.

According to the documentation, this can only happen if the count parameter is less than zero. But glUniform1i /doesn't have a count parameter/!

I've tried:

glUniform1iv(tilesUniformIndex, 1, new int[]{GL_TEXTURE0 + TILE_TEXTURE_UNIT_INDEX});


as well, and the implementation of that does what it looks like (passes a memory pointer to the array data as output value).

So, what gives? Anyone know how this function can possibly behave like this? This is a simple, correct use case, right?

• GL_TEXTURE0 + TILE_TEXTURE_UNIT_INDEX You don't set sampler uniforms to OpenGL enumerators. You set them to the actual texture unit index. This isn't your actual problem, but it's non-functional never-the-less. – Nicol Bolas Oct 17 '19 at 2:07
• I take it the shader compiled successfully at both stages ? (compile & link) – PaulHK Oct 18 '19 at 2:17
• Yup. (the first glok() not throwing an exception indicates this, but I also checked GL_LINK_STATUS with glProgram...) – BadZen Oct 18 '19 at 3:11
• I notice you're using a sampler2DArray, which isn't part of the GLSL spec (google tells me its an nvidia extension). But your glUniform1i example looks like it assuming the variable is a "sampler2D" - is this intentional ? This is in addition to Nicol Bolas's point about the GL_TEXTURE0 issue. – PaulHK Oct 31 '19 at 9:40
• sampler2Darray has been core GL since 3.0 / GLSL330. It was an extension before that but it certainly, definitely, absolutely supported (wokring now, core profile, not nvidia hardware, no extensions, etc) – BadZen Nov 25 '19 at 16:37