{"record":{"id":"c6160ba613a03eaa","repo":"mrdoob/three.js","slug":"unable-to-determine-texture-byte-length-for-form","errorCode":null,"errorMessage":"Unable to determine texture byte length for ${format} format.","messagePattern":"Unable to determine texture byte length for (.+?) format\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/extras/TextureUtils.js","lineNumber":197,"sourceCode":"\t\t\treturn Math.floor( ( width + 11 ) / 12 ) * Math.floor( ( height + 11 ) / 12 ) * 16;\n\n\t\t// https://registry.khronos.org/webgl/extensions/EXT_texture_compression_bptc/\n\t\tcase RGBA_BPTC_Format:\n\t\tcase RGB_BPTC_SIGNED_Format:\n\t\tcase RGB_BPTC_UNSIGNED_Format:\n\t\t\treturn Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 16;\n\n\t\t// https://registry.khronos.org/webgl/extensions/EXT_texture_compression_rgtc/\n\t\tcase RED_RGTC1_Format:\n\t\tcase SIGNED_RED_RGTC1_Format:\n\t\t\treturn Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 8;\n\t\tcase RED_GREEN_RGTC2_Format:\n\t\tcase SIGNED_RED_GREEN_RGTC2_Format:\n\t\t\treturn Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 16;\n\n\t}\n\n\tthrow new Error(\n\t\t`Unable to determine texture byte length for ${format} format.`,\n\t);\n\n}\n\nfunction getTextureTypeByteLength( type ) {\n\n\tswitch ( type ) {\n\n\t\tcase UnsignedByteType:\n\t\tcase ByteType:\n\t\t\treturn { byteLength: 1, components: 1 };\n\t\tcase UnsignedShortType:\n\t\tcase ShortType:\n\t\tcase HalfFloatType:\n\t\t\treturn { byteLength: 2, components: 1 };\n\t\tcase UnsignedShort4444Type:\n\t\tcase UnsignedShort5551Type:","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/mrdoob/three.js/blob/da05705fa31f02710c19772a2aa70c7454807f0c/src/extras/TextureUtils.js#L179-L215","documentation":"Thrown by the internal getTextureByteLength(width, height, format, type) helper (exposed as TextureUtils.getByteLength) when the supplied pixel format is not one of the recognized compressed or uncompressed formats handled by its switch statement. The function computes byte size per format-specific block layout; an unrecognized format has no known size formula.","triggerScenarios":"Calling THREE.TextureUtils.getByteLength(w, h, format, type) with a format constant outside the supported set. Passing a numeric raw value, undefined, or a deprecated format constant. Using a compressed texture format the running three.js revision does not enumerate (e.g. older build missing a newer extension format).","commonSituations":"Computing mipmap/texture memory budgets for an exotic or device-specific compressed format. Passing the format enum from a different three.js version where the numeric IDs differ. Accidentally swapping the format and type arguments. Using a custom PixelFormat constant.","solutions":["Pass a format constant exported by THREE (e.g. THREE.RGBAFormat, THREE.RGBA_ASTC_8x8_Format) and ensure your three.js version supports it.","Check argument order: signature is getByteLength(width, height, format, type) - format before type.","If you need a size estimate for an unsupported format, compute it yourself instead of relying on this helper.","Upgrade three.js to a revision that enumerates your compressed format, or fall back to an uncompressed format like RGBAFormat."],"exampleFix":"// before: raw/unknown numeric format\nconst bytes = THREE.TextureUtils.getByteLength(w, h, 9999, THREE.UnsignedByteType);\n\n// after: use a recognized format constant\nconst bytes = THREE.TextureUtils.getByteLength(w, h, THREE.RGBAFormat, THREE.UnsignedByteType);","handlingStrategy":"validation","validationCode":"import * as THREE from 'three';\n\nconst KNOWN_FORMATS = new Set(Object.values(THREE).filter(v => typeof v === 'number'));\n\nfunction safeByteLength(w, h, format, type) {\n  if (!KNOWN_FORMATS.has(format)) {\n    throw new Error(`Unsupported texture format: ${format}`);\n  }\n  return THREE.TextureUtils.getByteLength(w, h, format, type);\n}","typeGuard":"function isKnownFormat(format, three) {\n  return Object.values(three).includes(format);\n}","tryCatchPattern":"try {\n  bytes = THREE.TextureUtils.getByteLength(w, h, format, type);\n} catch (e) {\n  // format unsupported - fall back to an RGBA estimate\n  bytes = w * h * 4;\n}","preventionTips":["Pass format constants from the same three.js build you import.","Keep argument order straight: (width, height, format, type).","Prefer RGBAFormat when you do not need a specific compressed format."],"tags":["threejs","texture","compressed-texture","format","textureutils"],"backgroundTag":null,"analyzedSha":"da05705fa31f02710c19772a2aa70c7454807f0c","analyzedAt":"2026-08-12T22:51:37.160Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}