google/ExoPlayer · error · IllegalStateException
No call to setSamplerTexId() before bind.
Error message
No call to setSamplerTexId() before bind.
What it means
Thrown by GlProgram.bindAttributes()/setUniformsAndBindTextures() path when a shader declares a sampler uniform (GL_SAMPLER_2D, GL_SAMPLER_EXTERNAL_OES, or GL_SAMPLER_EXTERNAL_2D_Y2Y_EXT) whose texture id is still the default 0. GlProgram requires every sampler uniform to be assigned a real GL texture via setSamplerTexId(uniformName, texId, texUnitIndex) before the program is bound for drawing; texId 0 means 'never set'.
Source
Thrown at library/common/src/main/java/com/google/android/exoplayer2/util/GlProgram.java:427
case GLES20.GL_FLOAT_VEC3:
GLES20.glUniform3fv(location, /* count= */ 1, floatValue, /* offset= */ 0);
GlUtil.checkGlError();
break;
case GLES20.GL_FLOAT_MAT3:
GLES20.glUniformMatrix3fv(
location, /* count= */ 1, /* transpose= */ false, floatValue, /* offset= */ 0);
GlUtil.checkGlError();
break;
case GLES20.GL_FLOAT_MAT4:
GLES20.glUniformMatrix4fv(
location, /* count= */ 1, /* transpose= */ false, floatValue, /* offset= */ 0);
GlUtil.checkGlError();
break;
case GLES20.GL_SAMPLER_2D:
case GLES11Ext.GL_SAMPLER_EXTERNAL_OES:
case GL_SAMPLER_EXTERNAL_2D_Y2Y_EXT:
if (texIdValue == 0) {
throw new IllegalStateException("No call to setSamplerTexId() before bind.");
}
GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + texUnitIndex);
GlUtil.checkGlError();
GlUtil.bindTexture(
type == GLES20.GL_SAMPLER_2D
? GLES20.GL_TEXTURE_2D
: GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
texIdValue);
GLES20.glUniform1i(location, texUnitIndex);
GlUtil.checkGlError();
break;
default:
throw new IllegalStateException("Unexpected uniform type: " + type);
}
}
}
}
View on GitHub (pinned to dd430f7053)
Solutions
- Call glProgram.setSamplerTexId("uTexSampler", texId, /* texUnitIndex= */ 0) for every sampler declared in the shader before drawing
- Verify the texture id is non-zero: create/fill the texture (GlUtil.createTexture / SurfaceTexture updateTexImage) first and assert texId != 0
- Cross-check the sampler uniform name string exactly matches the GLSL declaration (names are looked up per-uniform)
- If a sampler is genuinely unused in a variant shader, remove it from that shader's GLSL rather than leaving it unbound
Example fix
// before
GlProgram program = new GlProgram(vertexShader, fragmentShader); // fragment has sampler2D uTexSampler
program.setBufferAttribs(...);
program.draw(); // IllegalStateException: no setSamplerTexId
// after
int texId = GlUtil.createTexture(GLES20.GL_TEXTURE_2D, width, height, false);
program.setSamplerTexId("uTexSampler", texId, /* texUnitIndex= */ 0);
program.draw(); Defensive patterns
Strategy: validation
Validate before calling
if (texId == 0) {
throw new IllegalStateException("Texture not created before binding program");
} Try / catch
Not applicable — the exception indicates a missing setup call; add setSamplerTexId instead of catching.
Prevention
- Write a helper that creates the GlProgram AND registers all samplers in one place
- Assert after program creation: iterate declared sampler names and require setSamplerTexId to have been called
- Keep shader uniform names as constants shared with the Java registration code
When it happens
Trigger: Creating a GlProgram from a fragment shader with 'uniform sampler2D uTexSampler;' (or smpExternalOES) and calling setUniformsAndBindTextures()/draw without ever calling setSamplerTexId for that uniform name, or passing texId=0 because the texture was not yet created/allocated.
Common situations: Migrating raw GLES20 effect code to GlProgram and forgetting the new sampler registration step; conditional code paths that skip setSamplerTexId for one of multiple samplers; trying to bind before an external OES texture from MediaCodec/SurfaceTexture was created; typo in the uniform name string so setSamplerTexId silently set a different (unused) uniform.
Related errors
- Unexpected uniform type: {type}
- glError: {gluErrorString(error)}
- width or height is less than 0
- Unsupported color transfer: {colorTransfer}
- eglCreateContext() failed to create a valid context. The dev
AI-assisted analysis of google/ExoPlayer@dd430f7053 (2026-08-14).
Data as JSON: /api/errors/c57be70cdbc47cff.
Report an issue: GitHub.