libgdx/libgdx · error · GdxRuntimeException

buffer type not supported

Error message

buffer type not supported

What it means

Thrown by Lwjgl3GL32.glReadnPixels when the destination data buffer is not a ByteBuffer, IntBuffer, ShortBuffer, or FloatBuffer. LWJGL's GL45.glReadnPixels has exactly those four overloads; other buffer types cannot be dispatched. Note the method also temporarily sets data.limit(bufSize) around the read.

Source

Thrown at backends/gdx-backend-lwjgl3/src/com/badlogic/gdx/backends/lwjgl3/Lwjgl3GL32.java:272

	}

	@Override
	public void glReadnPixels (int x, int y, int width, int height, int format, int type, int bufSize, Buffer data) {
		if (data == null) {
			GL45.glReadnPixels(x, y, width, height, format, type, bufSize, 0L);
		} else {
			int oldLimit = data.limit();
			data.limit(bufSize);
			if (data instanceof ByteBuffer) {
				GL45.glReadnPixels(x, y, width, height, format, type, (ByteBuffer)data);
			} else if (data instanceof IntBuffer) {
				GL45.glReadnPixels(x, y, width, height, format, type, (IntBuffer)data);
			} else if (data instanceof ShortBuffer) {
				GL45.glReadnPixels(x, y, width, height, format, type, (ShortBuffer)data);
			} else if (data instanceof FloatBuffer) {
				GL45.glReadnPixels(x, y, width, height, format, type, (FloatBuffer)data);
			} else {
				throw new GdxRuntimeException("buffer type not supported");
			}
			data.limit(oldLimit);
		}
	}

	@Override
	public void glGetnUniformfv (int program, int location, FloatBuffer params) {
		GL45.glGetnUniformfv(program, location, params);
	}

	@Override
	public void glGetnUniformiv (int program, int location, IntBuffer params) {
		GL45.glGetnUniformiv(program, location, params);
	}

	@Override
	public void glGetnUniformuiv (int program, int location, IntBuffer params) {
		GL45.glGetnUniformuiv(program, location, params);

View on GitHub (pinned to 97f4086187)

Solutions

  1. Allocate the readback target as ByteBuffer (GL_UNSIGNED_BYTE/GL_RGBA reads) or a type-matched Int/Short/FloatBuffer.
  2. Check bufSize <= data.capacity() before calling.
  3. For normal screenshots prefer Gdx.graphics.getBackBufferContents() or PixmapPixmap screenshot helpers instead of raw GL calls.

Example fix

// before
DoubleBuffer data = Buffers.newDoubleBuffer(w * h * 4);
Gdx.gl32.glReadnPixels(0, 0, w, h, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, w * h * 4, data);

// after
ByteBuffer data = ByteBuffer.allocateDirect(w * h * 4).order(ByteOrder.nativeOrder());
Gdx.gl32.glReadnPixels(0, 0, w, h, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, w * h * 4, data);
Defensive patterns

Strategy: type-guard

Validate before calling

static boolean isReadnPixelsBuffer(java.nio.Buffer b) {
    return b instanceof ByteBuffer || b instanceof IntBuffer || b instanceof ShortBuffer || b instanceof FloatBuffer;
}
static int bytesPerPixel(int format, int type) { /* GL_RGBA/GL_UNSIGNED_BYTE -> 4, etc. */ return 4; }

Type guard

static boolean canReadnPixels(java.nio.Buffer data, int bufSize) {
    return (data instanceof ByteBuffer || data instanceof IntBuffer || data instanceof ShortBuffer || data instanceof FloatBuffer)
        && bufSize <= data.capacity();
}

Prevention

When it happens

Trigger: Calling gl32.glReadnPixels(x, y, width, height, format, type, bufSize, data) with e.g. a DoubleBuffer, or any buffer type outside the four supported ones.

Common situations: Robust screenshot/pixel-readback code (glReadnPixels is the ARB_robustness safe variant); reading depth data into an unexpected buffer type; reusing a buffer allocated for another format.

Related errors


AI-assisted analysis of libgdx/libgdx@97f4086187 (2026-08-14). Data as JSON: /api/errors/2466d5f9d2aa2577. Report an issue: GitHub.