Godot: Invalid or unsupported DDS texture file

Created on 13 Jun 2020  ·  4Comments  ·  Source: godotengine/godot

Godot version:
3.2.1

OS/device including version:
Linux, nvidia proprietary drivers, GLES3 backend

Issue description:
I have some DDS texture files I try to import from an old non-godot project, and they fail to import, with message "Invalid or unsupported DDS texture file".

The texture file seems valid, as it it properly loaded by gimp or other tools. It is reported by some tools as: _Microsoft DirectDraw Surface (DDS): 256 x 256, compressed using DXT1_.

Steps to reproduce:

  • Load the provided DDS file to a material

Minimal godot project to reproduce:
bugreport.zip

bug confirmed import

Most helpful comment

Here's the relevant code:
https://github.com/godotengine/godot/blob/58034f39829b8b95a3e5d4c6e8d1ab0427371548/modules/dds/texture_loader_dds.cpp#L131-L133

I put a breakpoint with gdb and for the problematic file, the magic and hsize checks pass, but what fails is !(flags & DDSD_CAPS)), as the file's flags do not include DDSD_CAPS (0x1).
The flags value is 659462 (0xA1006).

Looking at the MSDN docs, they say that DDSD_CAPS is "Required in every .dds file", so it would seem that this file is invalid.

But at the same time they also say:

When you write .dds files, you should set the DDSD_CAPS and DDSD_PIXELFORMAT flags, and for mipmapped textures you should also set the DDSD_MIPMAPCOUNT flag. However, when you read a .dds file, you should not rely on the DDSD_CAPS, DDSD_PIXELFORMAT, and DDSD_MIPMAPCOUNT flags being set because some writers of such a file might not set these flags.

Way to enforce a specification...
(╯°□°)╯︵ ┻━┻

So we should probably remove the flags check to validate the file, and instead assume sane default values when the flags are missing.

All 4 comments

Confirmed with 3.2.2-rc1 and the current master branch (b3bc5aafc) using the provided project.

Opening the DDS file in GIMP and resaving it with default settings seems to generate a functional DDS file for Godot.

Here's the relevant code:
https://github.com/godotengine/godot/blob/58034f39829b8b95a3e5d4c6e8d1ab0427371548/modules/dds/texture_loader_dds.cpp#L131-L133

I put a breakpoint with gdb and for the problematic file, the magic and hsize checks pass, but what fails is !(flags & DDSD_CAPS)), as the file's flags do not include DDSD_CAPS (0x1).
The flags value is 659462 (0xA1006).

Looking at the MSDN docs, they say that DDSD_CAPS is "Required in every .dds file", so it would seem that this file is invalid.

But at the same time they also say:

When you write .dds files, you should set the DDSD_CAPS and DDSD_PIXELFORMAT flags, and for mipmapped textures you should also set the DDSD_MIPMAPCOUNT flag. However, when you read a .dds file, you should not rely on the DDSD_CAPS, DDSD_PIXELFORMAT, and DDSD_MIPMAPCOUNT flags being set because some writers of such a file might not set these flags.

Way to enforce a specification...
(╯°□°)╯︵ ┻━┻

So we should probably remove the flags check to validate the file, and instead assume sane default values when the flags are missing.

Thanks for your fast analysis!
Well, to be honest, this file may come from an old Microsoft Game Studios game I'm trying to revive 🤫. Amazing that they would write incorrect DDS.
I don't know how many "broken" DDS files such as this one may be in the wild, or if it's a good thing to allow to read them. The fact that Gimp or other software allow it may be an indicator that there may be some of them.

Maybe we can allow them and add a warning.

Was this page helpful?
0 / 5 - 0 ratings