mrdoob/three.js · error

Unable to determine texture byte length for ${format} format

Error message

Unable to determine texture byte length for ${format} format.

What it means

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.

Source

Thrown at src/extras/TextureUtils.js:197

			return Math.floor( ( width + 11 ) / 12 ) * Math.floor( ( height + 11 ) / 12 ) * 16;

		// https://registry.khronos.org/webgl/extensions/EXT_texture_compression_bptc/
		case RGBA_BPTC_Format:
		case RGB_BPTC_SIGNED_Format:
		case RGB_BPTC_UNSIGNED_Format:
			return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 16;

		// https://registry.khronos.org/webgl/extensions/EXT_texture_compression_rgtc/
		case RED_RGTC1_Format:
		case SIGNED_RED_RGTC1_Format:
			return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 8;
		case RED_GREEN_RGTC2_Format:
		case SIGNED_RED_GREEN_RGTC2_Format:
			return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 16;

	}

	throw new Error(
		`Unable to determine texture byte length for ${format} format.`,
	);

}

function getTextureTypeByteLength( type ) {

	switch ( type ) {

		case UnsignedByteType:
		case ByteType:
			return { byteLength: 1, components: 1 };
		case UnsignedShortType:
		case ShortType:
		case HalfFloatType:
			return { byteLength: 2, components: 1 };
		case UnsignedShort4444Type:
		case UnsignedShort5551Type:

View on GitHub (pinned to da05705fa3)

Solutions

  1. Pass a format constant exported by THREE (e.g. THREE.RGBAFormat, THREE.RGBA_ASTC_8x8_Format) and ensure your three.js version supports it.
  2. Check argument order: signature is getByteLength(width, height, format, type) - format before type.
  3. If you need a size estimate for an unsupported format, compute it yourself instead of relying on this helper.
  4. Upgrade three.js to a revision that enumerates your compressed format, or fall back to an uncompressed format like RGBAFormat.

Example fix

// before: raw/unknown numeric format
const bytes = THREE.TextureUtils.getByteLength(w, h, 9999, THREE.UnsignedByteType);

// after: use a recognized format constant
const bytes = THREE.TextureUtils.getByteLength(w, h, THREE.RGBAFormat, THREE.UnsignedByteType);
Defensive patterns

Strategy: validation

Validate before calling

import * as THREE from 'three';

const KNOWN_FORMATS = new Set(Object.values(THREE).filter(v => typeof v === 'number'));

function safeByteLength(w, h, format, type) {
  if (!KNOWN_FORMATS.has(format)) {
    throw new Error(`Unsupported texture format: ${format}`);
  }
  return THREE.TextureUtils.getByteLength(w, h, format, type);
}

Type guard

function isKnownFormat(format, three) {
  return Object.values(three).includes(format);
}

Try / catch

try {
  bytes = THREE.TextureUtils.getByteLength(w, h, format, type);
} catch (e) {
  // format unsupported - fall back to an RGBA estimate
  bytes = w * h * 4;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of mrdoob/three.js@da05705fa3 (2026-08-12). Data as JSON: /api/errors/c6160ba613a03eaa. Report an issue: GitHub.