FyroxEngine/Fyrox · error

Pixel types must match!

Error message

Pixel types must match!

What it means

While generating mip maps during texture import, the code resizes/copy-converts the image to the next mip level and expects the resulting pixel format to equal the source's. 'Pixel types must match!' means the downscaled image came back with a different pixel type, which the importer treats as an unrecoverable invariant break.

Solutions

  1. Disable mip map generation in TextureImportOptions (with_mip_maps(false)) or pre-generate mips offline in a tool.
  2. Convert the source image to a standard pixel kind (e.g. RGBA8) before import using image::DynamicImage::to_rgba8().
  3. Check/import with default import options to isolate whether a custom option (mul_div_alpha, cropping, mip_filter) causes the pixel type change; then adjust the option.

Example fix

// before
let texture = Texture::load_from_memory(
    bytes,
    TextureKind::D2 { width, height },
    TexturePixelKind::BC7Srgb,
    TextureImportOptions::default().with_mip_maps(true),
)?; // panics generating mips
// after
let texture = Texture::load_from_memory(
    bytes,
    TextureKind::D2 { width, height },
    TexturePixelKind::RGBA8Srgb,
    TextureImportOptions::default().with_mip_maps(true),
)?;
Defensive patterns

Strategy: validation

Validate before calling

let img = image::load_from_memory(bytes)?.to_rgba8(); // ensure uniform pixel type before mip generation

Prevention

When it happens

Trigger: Importing a texture whose image crate operations (resize/generate_mipmaps with mul_div_alpha, cropping, or custom pixel kind) produce a different pixel type than the base level — typically with unusual pixel kinds (e.g. compressed or float formats) that the mip generator cannot preserve.

Common situations: Importing HDR/BC-compressed textures with mip map generation enabled; custom import options (mip_filter/cropping) that change the pixel representation; version drift between the image crate and fyrox-texture changing returned pixel types.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


AI-assisted analysis of FyroxEngine/Fyrox@76c91aad8e (2026-09-10). Data as JSON: /api/errors/07ea3ff8cdad6190. Report an issue: GitHub.

Appendix: source

Thrown at fyrox-texture/src/lib.rs:1663

                    if mip_count != 0 {
                        let mut dst_img =
                            fr::images::Image::new(level_width, level_height, src_pixel_type);

                        let mut resizer = fr::Resizer::new();

                        resizer
                            .resize(
                                &current_level,
                                &mut dst_img,
                                Some(&ResizeOptions {
                                    algorithm: fr::ResizeAlg::Convolution(
                                        import_options.mip_filter.into_filter_type(),
                                    ),
                                    cropping: Default::default(),
                                    mul_div_alpha: true,
                                }),
                            )
                            .expect("Pixel types must match!");

                        current_level = dst_img;
                    }

                    mip_count += 1;

                    if import_options.compression == CompressionOptions::NoCompression {
                        bytes.extend_from_slice(current_level.buffer())
                    } else if let Some((compressed_data, new_pixel_kind)) = try_compress(
                        src_pixel_kind,
                        current_level.buffer(),
                        level_width as usize,
                        level_height as usize,
                        import_options.compression,
                    ) {
                        final_pixel_kind = new_pixel_kind;
                        bytes.extend_from_slice(&compressed_data);
                    } else {

View on GitHub (pinned to 76c91aad8e)