{"record":{"id":"6eb94e44c8ef130a","repo":"stride3d/stride","slug":"alphaloadmode-alphaloadmode-not-supported-for-dds-source","errorCode":null,"errorMessage":"AlphaLoadMode.{alphaLoadMode} not supported for DDS (source premultiplied-state cannot be reliably determined).","messagePattern":"AlphaLoadMode\\.(.+?) not supported for DDS \\(source premultiplied-state cannot be reliably determined\\)\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Foundation/Graphics/DDSHelper.cs","lineNumber":1000,"sourceCode":"        /// </summary>\n        /// <param name=\"pSource\"></param>\n        /// <param name=\"size\"></param>\n        /// <param name=\"handle\"></param>\n        /// <returns></returns>\n        public static unsafe Image LoadFromDDSMemory(IntPtr pSource, int size, bool makeACopy, GCHandle? handle, AlphaLoadMode alphaLoadMode)\n        {\n            var flags = makeACopy ? DDSFlags.CopyMemory : DDSFlags.None;\n\n            ConversionFlags convFlags;\n            ImageDescription mdata;\n            // If the memory pointed is not a DDS memory, return null.\n            if (!DecodeDDSHeader(pSource, size, flags, out mdata, out convFlags))\n                return null;\n\n            // DDS has no portable premul-state flag for plain BGRA/RGBA payloads (DX10 AlphaLoadMode is\n            // only present in the HeaderDXT10 extension), so we can't safely convert blindly.\n            if (alphaLoadMode != AlphaLoadMode.Preserve)\n                throw new NotSupportedException($\"AlphaLoadMode.{alphaLoadMode} not supported for DDS (source premultiplied-state cannot be reliably determined).\");\n\n            int offset = sizeof (uint) + Unsafe.SizeOf<DDS.Header>();\n            if ((convFlags & ConversionFlags.DX10) != 0)\n                offset += Unsafe.SizeOf<DDS.HeaderDXT10>();\n\n            var pal8 = (uint*) 0;\n            if ((convFlags & ConversionFlags.Pal8) != 0)\n            {\n                pal8 = (uint*) ((byte*) (pSource) + offset);\n                offset += (256 * sizeof (uint));\n            }\n\n            if (size < offset)\n                throw new InvalidOperationException();\n\n            var image = CreateImageFromDDS(pSource, offset, size - offset, mdata, (flags & DDSFlags.LegacyDword) != 0 ? Image.PitchFlags.LegacyDword : Image.PitchFlags.None, convFlags, pal8, handle);\n            return image;\n        }","sourceCodeStart":982,"sourceCodeEnd":1018,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Foundation/Graphics/DDSHelper.cs#L982-L1018","documentation":"Thrown when decoding a DDS texture with an alphaLoadMode other than AlphaLoadMode.Preserve. DDS files carry no portable flag indicating whether plain BGRA/RGBA payloads are premultiplied (the premul state only exists in the DX10 extension), so the library cannot safely convert between straight and premultiplied alpha and refuses any explicit mode.","triggerScenarios":"Calling a DDS decode API that accepts an AlphaLoadMode parameter with AlphaLoadMode.Straight or AlphaLoadMode.Premultiplied instead of AlphaLoadMode.Preserve.","commonSituations":"Porting loader code that used PNG/TGA-style alpha handling and passing an explicit alpha mode to the DDS loader; pipeline code that globally sets a premultiplied-alpha policy for all texture formats.","solutions":["Pass AlphaLoadMode.Preserve when loading DDS textures.","If conversion is truly required, decode with Preserve and convert explicitly after checking the DX10 HeaderDXT10 AlphaMode when present (or the asset's known convention).","Catch NotSupportedException around the decode and fall back to Preserve."],"exampleFix":"// before\nvar tex = DdsLoader.Load(stream, AlphaLoadMode.Premultiplied);\n\n// after\nvar tex = DdsLoader.Load(stream, AlphaLoadMode.Preserve);\n// premul conversion must be done explicitly after decode, not requested here","handlingStrategy":"validation","validationCode":"if (alphaLoadMode != AlphaLoadMode.Preserve)\n    throw new NotSupportedException(\"DDS decode requires AlphaLoadMode.Preserve; convert premul state explicitly after decode\");","typeGuard":"bool IsDdsSafeAlphaMode(AlphaLoadMode m) => m == AlphaLoadMode.Preserve;","tryCatchPattern":"try { tex = DdsLoader.Load(stream, alphaLoadMode); }\ncatch (NotSupportedException e) when (e.Message.Contains(\"AlphaLoadMode\"))\n{\n    tex = DdsLoader.Load(stream, AlphaLoadMode.Preserve);\n    tex = ApplyAlphaConversion(tex, alphaLoadMode); // explicit, caller-verified\n}","preventionTips":["Default all DDS loads to AlphaLoadMode.Preserve","Keep alpha-mode policy code format-specific, not global","Only convert premul state when the source format documents it (e.g. DX10 AlphaMode)"],"tags":["dds","alpha","unsupported-mode"],"backgroundTag":"unsupported-enum-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}