stride3d/stride · warning · ArgumentException

' ' is already an sRGB pixel format

Error message

'{format}' is already an sRGB pixel format

What it means

The HasSRgbEquivalent property accessor on the PixelFormat helper throws ArgumentException when the wrapped format IsSRgb, because asking for an sRGB equivalent of a format that is already sRGB is meaningless. The property is intended for non-sRGB formats; for sRGB formats it throws instead of returning a value.

Solutions

  1. Check format.IsSRgb first and skip/short-circuit for already-sRGB formats.
  2. Return the format itself when IsSRgb is true instead of querying HasSRgbEquivalent.
  3. Filter the format list to non-sRGB entries before calling this property.

Example fix

// before
var srgbFmt = helper.HasSRgbEquivalent ? helper.GetSRgbEquivalent() : helper.Format;
// after
var srgbFmt = helper.Format.IsSRgb ? helper.Format
    : helper.HasSRgbEquivalent ? helper.GetSRgbEquivalent() : helper.Format;
Defensive patterns

Strategy: type-guard

Validate before calling

if (!format.IsSRgb)
{
    // safe to query
    var has = helper.HasSRgbEquivalent;
}

Type guard

bool CanQuerySRgbEquivalent(PixelFormat fmt) => !fmt.IsSRgb;

Try / catch

try { return helper.HasSRgbEquivalent ? helper.GetSRgbEquivalent() : helper.Format; }
catch (ArgumentException) { return helper.Format; /* already sRGB */ }

Prevention

When it happens

Trigger: Evaluating helper.HasSRgbEquivalent on a PixelFormatExtensions instance whose format is already an sRGB format (e.g. R8G8B8A8_UNorm_SRgb), typically inside generic format-handling code that does not branch on IsSRgb first.

Common situations: Generic texture-format migration code adding _SRgb variants that double-applies to already-sRGB formats; asset pipelines iterating formats where sRGB inputs slip through; debugging code that probes all formats indiscriminately.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/b2b16fdc846baff9. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Foundation/Graphics/PixelFormatExtensions.cs:273

        ///   They are often used in scenarios where the same data may be interpreted
        ///   as different types depending on the context, such as when creating
        ///   a resource that can be viewed in multiple ways.
        /// </remarks>
        public bool IsTypeless => typelessFormats[GetIndex(format)];

        /// <summary>
        ///   Gets a value indicating if the <see cref="PixelFormat"/> has an equivalent sRGB format.
        /// </summary>
        /// <returns>
        ///   <see langword="true"/> if the pixel format has an sRGB equivalent;
        ///   <see langword="false"/> otherwise.
        /// </returns>
        /// <exception cref="ArgumentException">
        ///   The provided pixel format is already an sRGB format.
        /// </exception>
        public bool HasSRgbEquivalent
            => format.IsSRgb
                ? throw new ArgumentException($"'{format}' is already an sRGB pixel format", nameof(format))
                : sRgbConversion.ContainsKey(format);

        /// <summary>
        ///   Gets a value indicating if the <see cref="PixelFormat"/> has an equivalent non-sRGB format.
        /// </summary>
        /// <returns>
        ///   <see langword="true"/> if the pixel format has an non-sRGB equivalent;
        ///   <see langword="false"/> otherwise.
        /// </returns>
        /// <exception cref="ArgumentException">
        ///   The provided pixel format is not an sRGB format.
        /// </exception>
        public bool HasNonSRgbEquivalent
            => !format.IsSRgb
                ? throw new ArgumentException($"'{format}' is not a sRGB format", nameof(format))
                : sRgbConversion.ContainsKey(format);

        /// <summary>

View on GitHub (pinned to 96fad776d2)