{"record":{"id":"42a84d3ea8d58b5d","repo":"mrdoob/three.js","slug":"three-textureutils-unknown-texture-type-type","errorCode":null,"errorMessage":"THREE.TextureUtils: Unknown texture type ${type}.","messagePattern":"THREE\\.TextureUtils: Unknown texture type (.+?)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/extras/TextureUtils.js","lineNumber":227,"sourceCode":"\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:\n\t\t\treturn { byteLength: 2, components: 4 };\n\t\tcase UnsignedIntType:\n\t\tcase IntType:\n\t\tcase FloatType:\n\t\t\treturn { byteLength: 4, components: 1 };\n\t\tcase UnsignedInt5999Type:\n\t\tcase UnsignedInt101111Type:\n\t\t\treturn { byteLength: 4, components: 3 };\n\n\t}\n\n\tthrow new Error( `THREE.TextureUtils: Unknown texture type ${type}.` );\n\n}\n\n/**\n * A class containing utility functions for textures.\n *\n * @hideconstructor\n */\nclass TextureUtils {\n\n\t/**\n\t * Scales the texture as large as possible within its surface without cropping\n\t * or stretching the texture. The method preserves the original aspect ratio of\n\t * the texture. Akin to CSS `object-fit: contain`\n\t *\n\t * @param {Texture} texture - The texture.\n\t * @param {number} aspect - The texture's aspect ratio.\n\t * @return {Texture} The updated texture.","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/mrdoob/three.js/blob/da05705fa31f02710c19772a2aa70c7454807f0c/src/extras/TextureUtils.js#L209-L245","documentation":"Thrown by getTextureTypeByteLength(type) when the texture data type is not among the recognized constants (UnsignedByteType, ByteType, UnsignedShortType, ShortType, UnsignedShort5551Type, UnsignedIntType, IntType, FloatType, UnsignedInt5999Type, UnsignedInt101111Type). The function maps each type to a {byteLength, components} pair used to size uncompressed textures; unknown types have no mapping.","triggerScenarios":"Calling TextureUtils.getByteLength with a type constant outside the supported set, or passing undefined/NaN for the type argument. Swapping format and type so an invalid value lands in the type slot. Using a HalfFloatType on a three.js build where its case is not present.","commonSituations":"Confusing the format and type argument positions. Using a numeric type ID from an incompatible three.js version. Forgetting to import the type constant so it resolves to undefined.","solutions":["Pass a valid THREE texture type constant for the type argument (e.g. THREE.UnsignedByteType, THREE.FloatType, THREE.HalfFloatType).","Verify argument order is (width, height, format, type); type is the fourth argument.","Ensure the constant is imported and not undefined at runtime.","Upgrade three.js to a revision that includes your type in the switch."],"exampleFix":"// before: type slot gets an invalid value\nconst b = THREE.TextureUtils.getByteLength(w, h, THREE.RGBAFormat, 12345);\n\n// after: valid type constant\nconst b = THREE.TextureUtils.getByteLength(w, h, THREE.RGBAFormat, THREE.UnsignedByteType);","handlingStrategy":"validation","validationCode":"import * as THREE from 'three';\n\nconst VALID_TYPES = new Set([\n  THREE.UnsignedByteType, THREE.ByteType, THREE.UnsignedShortType, THREE.ShortType,\n  THREE.UnsignedShort5551Type, THREE.UnsignedIntType, THREE.IntType,\n  THREE.FloatType, THREE.UnsignedInt5999Type, THREE.UnsignedInt101111Type,\n]);\n\nif (!VALID_TYPES.has(type)) {\n  throw new Error(`Unsupported texture type: ${type}`);\n}","typeGuard":"function isValidTextureType(type, THREE) {\n  return [\n    THREE.UnsignedByteType, THREE.ByteType, THREE.UnsignedShortType, THREE.ShortType,\n    THREE.UnsignedShort5551Type, THREE.UnsignedIntType, THREE.IntType,\n    THREE.FloatType, THREE.UnsignedInt5999Type, THREE.UnsignedInt101111Type,\n  ].includes(type);\n}","tryCatchPattern":null,"preventionTips":["Confirm the type constant is imported (not undefined).","Remember type is the fourth argument to getByteLength.","Default to THREE.UnsignedByteType for standard 8-bit RGBA textures."],"tags":["threejs","texture","texture-type","textureutils"],"backgroundTag":null,"analyzedSha":"da05705fa31f02710c19772a2aa70c7454807f0c","analyzedAt":"2026-08-12T22:51:37.160Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}