{"record":{"id":"2466d5f9d2aa2577","repo":"libgdx/libgdx","slug":"buffer-type-not-supported","errorCode":null,"errorMessage":"buffer type not supported","messagePattern":"buffer type not supported","errorType":"exception","errorClass":"GdxRuntimeException","httpStatus":null,"severity":"error","filePath":"backends/gdx-backend-lwjgl3/src/com/badlogic/gdx/backends/lwjgl3/Lwjgl3GL32.java","lineNumber":272,"sourceCode":"\t}\n\n\t@Override\n\tpublic void glReadnPixels (int x, int y, int width, int height, int format, int type, int bufSize, Buffer data) {\n\t\tif (data == null) {\n\t\t\tGL45.glReadnPixels(x, y, width, height, format, type, bufSize, 0L);\n\t\t} else {\n\t\t\tint oldLimit = data.limit();\n\t\t\tdata.limit(bufSize);\n\t\t\tif (data instanceof ByteBuffer) {\n\t\t\t\tGL45.glReadnPixels(x, y, width, height, format, type, (ByteBuffer)data);\n\t\t\t} else if (data instanceof IntBuffer) {\n\t\t\t\tGL45.glReadnPixels(x, y, width, height, format, type, (IntBuffer)data);\n\t\t\t} else if (data instanceof ShortBuffer) {\n\t\t\t\tGL45.glReadnPixels(x, y, width, height, format, type, (ShortBuffer)data);\n\t\t\t} else if (data instanceof FloatBuffer) {\n\t\t\t\tGL45.glReadnPixels(x, y, width, height, format, type, (FloatBuffer)data);\n\t\t\t} else {\n\t\t\t\tthrow new GdxRuntimeException(\"buffer type not supported\");\n\t\t\t}\n\t\t\tdata.limit(oldLimit);\n\t\t}\n\t}\n\n\t@Override\n\tpublic void glGetnUniformfv (int program, int location, FloatBuffer params) {\n\t\tGL45.glGetnUniformfv(program, location, params);\n\t}\n\n\t@Override\n\tpublic void glGetnUniformiv (int program, int location, IntBuffer params) {\n\t\tGL45.glGetnUniformiv(program, location, params);\n\t}\n\n\t@Override\n\tpublic void glGetnUniformuiv (int program, int location, IntBuffer params) {\n\t\tGL45.glGetnUniformuiv(program, location, params);","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/libgdx/libgdx/blob/97f40861878058087be0685ca167ddfde132134b/backends/gdx-backend-lwjgl3/src/com/badlogic/gdx/backends/lwjgl3/Lwjgl3GL32.java#L254-L290","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Allocate the readback target as ByteBuffer (GL_UNSIGNED_BYTE/GL_RGBA reads) or a type-matched Int/Short/FloatBuffer.","Check bufSize <= data.capacity() before calling.","For normal screenshots prefer Gdx.graphics.getBackBufferContents() or PixmapPixmap screenshot helpers instead of raw GL calls."],"exampleFix":"// before\nDoubleBuffer data = Buffers.newDoubleBuffer(w * h * 4);\nGdx.gl32.glReadnPixels(0, 0, w, h, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, w * h * 4, data);\n\n// after\nByteBuffer data = ByteBuffer.allocateDirect(w * h * 4).order(ByteOrder.nativeOrder());\nGdx.gl32.glReadnPixels(0, 0, w, h, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, w * h * 4, data);","handlingStrategy":"type-guard","validationCode":"static boolean isReadnPixelsBuffer(java.nio.Buffer b) {\n    return b instanceof ByteBuffer || b instanceof IntBuffer || b instanceof ShortBuffer || b instanceof FloatBuffer;\n}\nstatic int bytesPerPixel(int format, int type) { /* GL_RGBA/GL_UNSIGNED_BYTE -> 4, etc. */ return 4; }","typeGuard":"static boolean canReadnPixels(java.nio.Buffer data, int bufSize) {\n    return (data instanceof ByteBuffer || data instanceof IntBuffer || data instanceof ShortBuffer || data instanceof FloatBuffer)\n        && bufSize <= data.capacity();\n}","tryCatchPattern":null,"preventionTips":["Always read pixels into a direct ByteBuffer for GL_RGBA/GL_UNSIGNED_BYTE.","Check bufSize against buffer capacity before calling.","Prefer gdx screenshot helpers over raw glReadnPixels."],"tags":["opengl","lwjgl3","readback","pixels","type-mismatch","gdx"],"backgroundTag":null,"analyzedSha":"97f40861878058087be0685ca167ddfde132134b","analyzedAt":"2026-08-14T10:52:53.492Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}