{"record":{"id":"e4a061778559ca75","repo":"libgdx/libgdx","slug":"can-t-use-buffer-getclass-getname-with-t","errorCode":null,"errorMessage":"Can't use  + buffer.getClass().getName() +  with type  + type +  with this method. Use ByteBuffer and one of GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT or GL_FLOAT for type. Blame LWJGL","messagePattern":"Can't use  \\+ buffer\\.getClass\\(\\)\\.getName\\(\\) \\+  with type  \\+ type \\+  with this method\\. Use ByteBuffer and one of GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT or GL_FLOAT for type\\. Blame LWJGL","errorType":"exception","errorClass":"GdxRuntimeException","httpStatus":null,"severity":"error","filePath":"backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGL20.java","lineNumber":836,"sourceCode":"\n\tpublic void glVertexAttrib4fv (int indx, FloatBuffer values) {\n\t\tGL20.glVertexAttrib4f(indx, values.get(), values.get(), values.get(), values.get());\n\t}\n\n\tpublic void glVertexAttribPointer (int indx, int size, int type, boolean normalized, int stride, Buffer buffer) {\n\t\tif (buffer instanceof ByteBuffer) {\n\t\t\tif (type == GL_BYTE)\n\t\t\t\tGL20.glVertexAttribPointer(indx, size, false, normalized, stride, (ByteBuffer)buffer);\n\t\t\telse if (type == GL_UNSIGNED_BYTE)\n\t\t\t\tGL20.glVertexAttribPointer(indx, size, true, normalized, stride, (ByteBuffer)buffer);\n\t\t\telse if (type == GL_SHORT)\n\t\t\t\tGL20.glVertexAttribPointer(indx, size, false, normalized, stride, ((ByteBuffer)buffer).asShortBuffer());\n\t\t\telse if (type == GL_UNSIGNED_SHORT)\n\t\t\t\tGL20.glVertexAttribPointer(indx, size, true, normalized, stride, ((ByteBuffer)buffer).asShortBuffer());\n\t\t\telse if (type == GL_FLOAT)\n\t\t\t\tGL20.glVertexAttribPointer(indx, size, normalized, stride, ((ByteBuffer)buffer).asFloatBuffer());\n\t\t\telse\n\t\t\t\tthrow new GdxRuntimeException(\"Can't use \" + buffer.getClass().getName() + \" with type \" + type\n\t\t\t\t\t+ \" with this method. Use ByteBuffer and one of GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT or GL_FLOAT for type. Blame LWJGL\");\n\t\t} else if (buffer instanceof FloatBuffer) {\n\t\t\tif (type == GL_FLOAT)\n\t\t\t\tGL20.glVertexAttribPointer(indx, size, normalized, stride, (FloatBuffer)buffer);\n\t\t\telse\n\t\t\t\tthrow new GdxRuntimeException(\n\t\t\t\t\t\"Can't use \" + buffer.getClass().getName() + \" with type \" + type + \" with this method.\");\n\t\t} else\n\t\t\tthrow new GdxRuntimeException(\n\t\t\t\t\"Can't use \" + buffer.getClass().getName() + \" with this method. Use ByteBuffer instead. Blame LWJGL\");\n\t}\n\n\tpublic void glViewport (int x, int y, int width, int height) {\n\t\tGL11.glViewport(x, y, width, height);\n\t}\n\n\tpublic void glDrawElements (int mode, int count, int type, int indices) {\n\t\tGL11.glDrawElements(mode, count, type, indices);","sourceCodeStart":818,"sourceCodeEnd":854,"githubUrl":"https://github.com/libgdx/libgdx/blob/97f40861878058087be0685ca167ddfde132134b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGL20.java#L818-L854","documentation":"Thrown by LwjglGL20.glVertexAttribPointer when a ByteBuffer is bound as the attribute buffer but the type argument is none of GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT or GL_FLOAT. For each accepted type the backend reinterprets the ByteBuffer (asShortBuffer/asFloatBuffer) to satisfy LWJGL's typed overloads; other types — notably GL_UNSIGNED_INT and GL_FIXED — have no desktop overload path, hence 'Blame LWJGL'.","triggerScenarios":"Calling Gdx.gl20.glVertexAttribPointer(indx, size, GL_UNSIGNED_INT|GL_FIXED|..., normalized, stride, (ByteBuffer)buffer). Note: int attribute data cannot be passed via ByteBuffer here; and GL_FIXED is GLES-only.","commonSituations":"Porting Android meshes that use GL_FIXED (GLES1-era) or unsigned-int attributes; hand-written vertex layouts where the type constant was mistyped or copied from an index-buffer call.","solutions":["Use GL_FLOAT with a FloatBuffer (or ByteBuffer reinterpreted via asFloatBuffer) for float attribute data — the standard desktop path.","For integer attribute data, upload through an IntBuffer-backed VBO and the int-offset glVertexAttribPointer overload.","Replace GL_FIXED layouts with float layouts on desktop; fixed-point is not a desktop type."],"exampleFix":"// before\nGdx.gl20.glVertexAttribPointer(loc, 4, GL20.GL_UNSIGNED_INT, false, stride, byteBuffer); // throws\n\n// after\nGdx.gl20.glBindBuffer(GL20.GL_ARRAY_BUFFER, vboHandle);\nGdx.gl20.glVertexAttribPointer(loc, 4, GL20.GL_FLOAT, false, stride, 0);","handlingStrategy":"type-guard","validationCode":"private static final Set<Integer> BYTE_BUFFER_TYPES = Set.of(GL20.GL_BYTE, GL20.GL_UNSIGNED_BYTE, GL20.GL_SHORT, GL20.GL_UNSIGNED_SHORT, GL20.GL_FLOAT);\nif (buffer instanceof ByteBuffer && !BYTE_BUFFER_TYPES.contains(type)) throw new IllegalArgumentException(\"ByteBuffer supports BYTE/UBYTE/SHORT/USHORT/FLOAT only\");","typeGuard":"private static boolean isByteBufferAttribTypeOK(java.nio.Buffer b, int type) {\n    return !(b instanceof ByteBuffer) || type == GL20.GL_BYTE || type == GL20.GL_UNSIGNED_BYTE\n        || type == GL20.GL_SHORT || type == GL20.GL_UNSIGNED_SHORT || type == GL20.GL_FLOAT;\n}","tryCatchPattern":null,"preventionTips":["No GL_UNSIGNED_INT or GL_FIXED attributes via ByteBuffer on desktop — use VBO + int-offset overload.","Prefer float vertex layouts; they work everywhere."],"tags":["opengl","vertex-attributes","buffer","lwjgl"],"backgroundTag":null,"analyzedSha":"97f40861878058087be0685ca167ddfde132134b","analyzedAt":"2026-08-14T10:52:53.492Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}