Skip to content

fix GLSL shader compilation errors on non-C locales - #557

Merged
nschimme merged 9 commits into
MUME:masterfrom
nschimme:fix-glsl-shader-locale-compilation-bug-17562491324332354441
Sep 14, 2026
Merged

nschimme merged 9 commits into
MUME:masterfrom
nschimme:fix-glsl-shader-locale-compilation-bug-17562491324332354441

Conversation

@nschimme

@nschimme nschimme commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #556

Summary by Sourcery

Make legacy GLSL shader generation independent of the process locale and improve shader declaration compatibility.

Bug Fixes:

  • Ensure generated GLSL floating-point constants always use a dot decimal separator so shader compilation works under non-C locales.

Enhancements:

  • Add a locale-independent floating-point formatting utility and coverage for locale-sensitive output.
  • Update legacy shader array declarations for broader GLSL compiler compatibility.

Tests:

  • Add text utility tests verifying floating-point formatting remains dot-separated under a German locale.

- Use locale-invariant float string formatting (`text_utils::formatFloatClassic`)
  in ShaderUtils.cpp for preprocessor defines (WEATHER_RADIUS, etc.) to ensure
  a '.' decimal separator regardless of active system locale.
- Fix array declaration syntax in room/tex/acolor/vert.glsl from
  `const ivec3[4] ioffsets` to `const ivec3 ioffsets[4]` for compatibility
  with GLSL 3.30 and GLSL ES 3.00 (WebGL 2) compilers.
- Add unit test coverage in TestGlobal.
- Use locale-invariant float string formatting (`text_utils::formatFloatClassic`)
  in ShaderUtils.cpp for preprocessor defines (WEATHER_RADIUS, etc.) to ensure
  a '.' decimal separator regardless of active system locale.
- Fix array declaration syntax in room/tex/acolor/vert.glsl from
  `const ivec3[4] ioffsets` to `const ivec3 ioffsets[4]` for compatibility
  with GLSL 3.30 and GLSL ES 3.00 (WebGL 2) compilers.
- Add unit test coverage in TestGlobal.
- Use locale-invariant float string formatting (`text_utils::formatFloatClassic`)
  in ShaderUtils.cpp for preprocessor defines (WEATHER_RADIUS, etc.) to ensure
  a '.' decimal separator regardless of active system locale.
- Fix array declaration syntax in room/tex/acolor/vert.glsl from
  `const ivec3[4] ioffsets` to `const ivec3 ioffsets[4]` for compatibility
  with GLSL 3.30 and GLSL ES 3.00 (WebGL 2) compilers.
- Add unit test coverage in TestGlobal.
- Use locale-invariant float string formatting (`text_utils::formatFloatClassic`)
  in ShaderUtils.cpp for preprocessor defines (WEATHER_RADIUS, etc.) to ensure
  a '.' decimal separator regardless of active system locale.
- Fix array declaration syntax in room/tex/acolor/vert.glsl from
  `const ivec3[4] ioffsets` to `const ivec3 ioffsets[4]` for compatibility
  with GLSL 3.30 and GLSL ES 3.00 (WebGL 2) compilers.
- Add unit test coverage in TestGlobal.
- Use locale-invariant float string formatting (`text_utils::formatFloatClassic`)
  in ShaderUtils.cpp for preprocessor defines (WEATHER_RADIUS, etc.) to ensure
  a '.' decimal separator regardless of active system locale.
- Fix array declaration syntax in room/tex/acolor/vert.glsl from
  `const ivec3[4] ioffsets` to `const ivec3 ioffsets[4]` for compatibility
  with GLSL 3.30 and GLSL ES 3.00 (WebGL 2) compilers.
- Use RAII guard (`RAIICallback`) in unit test `testFormatFloatClassic` to ensure
  locale restoration on all exit paths.
- Use locale-invariant float string formatting (`text_utils::formatFloatClassic`)
  in ShaderUtils.cpp for preprocessor defines (WEATHER_RADIUS, etc.) to ensure
  a '.' decimal separator regardless of active system locale.
- Fix array declaration syntax in room/tex/acolor/vert.glsl from
  `const ivec3[4] ioffsets` to `const ivec3 ioffsets[4]` for compatibility
  with GLSL 3.30 and GLSL ES 3.00 (WebGL 2) compilers.
- Use RAII guard (`RAIICallback`) in unit test `testFormatFloatClassic` to ensure
  locale restoration on all exit paths.
- Use locale-invariant float string formatting (`text_utils::formatFloatClassic`)
  in ShaderUtils.cpp for preprocessor defines (WEATHER_RADIUS, etc.) to ensure
  a '.' decimal separator regardless of active system locale.
- Fix array declaration syntax in room/tex/acolor/vert.glsl from
  `const ivec3[4] ioffsets` to `const ivec3 ioffsets[4]` for compatibility
  with GLSL 3.30 and GLSL ES 3.00 (WebGL 2) compilers.
- Use RAII guard (`RAIICallback`) in unit test `testFormatFloatClassic` to ensure
  locale restoration on all exit paths.
- Use locale-invariant float string formatting (`text_utils::formatFloatClassic`)
  in ShaderUtils.cpp for preprocessor defines (WEATHER_RADIUS, etc.) to ensure
  a '.' decimal separator regardless of active system locale.
- Fix array declaration syntax in room/tex/acolor/vert.glsl from
  `const ivec3[4] ioffsets` to `const ivec3 ioffsets[4]` for compatibility
  with GLSL 3.30 and GLSL ES 3.00 (WebGL 2) compilers.
- Use RAII guard (`RAIICallback`) in unit test `testFormatFloatClassic` to ensure
  locale restoration on all exit paths.
- Use locale-invariant float string formatting (`text_utils::formatFloatClassic`)
  in ShaderUtils.cpp for preprocessor defines (WEATHER_RADIUS, etc.) to ensure
  a '.' decimal separator regardless of active system locale.
- Fix array declaration syntax in room/tex/acolor/vert.glsl from
  `const ivec3[4] ioffsets` to `const ivec3 ioffsets[4]` for compatibility
  with GLSL 3.30 and GLSL ES 3.00 (WebGL 2) compilers.
- Use RAII guard (`RAIICallback`) in unit test `testFormatFloatClassic` to ensure
  locale restoration on all exit paths.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @nschimme, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 9 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 14, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR fixes shader compilation under non-C locales by formatting generated weather constants with a classic locale so GLSL receives decimal points rather than locale-specific commas, adds locale-sensitive tests, and modernizes a legacy GLSL array declaration for compiler compatibility.

Sequence diagram for locale-safe GLSL shader generation

sequenceDiagram
    participant ShaderUtils
    participant TextUtils
    participant GLSLCompiler

    ShaderUtils->>TextUtils: formatFloatClassic(weatherConstant)
    TextUtils->>TextUtils: std::locale::classic()
    TextUtils-->>ShaderUtils: decimal-point string
    ShaderUtils->>GLSLCompiler: compileShader(shaderSourceWithWeatherDefines)
    GLSLCompiler-->>ShaderUtils: compiled shader
Loading

Flow diagram for locale-independent weather constants

flowchart LR
    A[Weather constants] --> B[formatFloatClassic]
    B --> C[GLSL weather defines with decimal points]
    C --> D[Shader compilation succeeds under non-C locales]
Loading

File-Level Changes

Change Details Files
Make generated GLSL numeric literals independent of the process locale.
  • Add a float formatter using a classic C++ locale and showpoint output.
  • Use the locale-stable formatter for weather-related shader preprocessor defines.
  • Add coverage that exercises formatting under a German locale.
src/global/TextUtils.cpp
src/global/TextUtils.h
src/opengl/legacy/ShaderUtils.cpp
Adjust a legacy GLSL array declaration for shader compiler compatibility.
  • Rewrite the array declarator to place the variable name before its dimensions in both conditional branches.
src/resources/shaders/legacy/room/tex/acolor/vert.glsl

Assessment against linked issues

Issue Objective Addressed Explanation
#556 Ensure generated GLSL numeric constants use a locale-independent decimal point so shader source remains valid when the system locale uses commas. ✅
#556 Correct the GLSL array declaration syntax so shaders compile on the affected GLSL 4.20 implementations. ✅
#556 Prevent shader compilation failure and the resulting startup abort on affected Intel HD 4000/Mesa and other older GLSL implementations. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@nschimme
nschimme merged commit b4d8d58 into MUME:master Sep 14, 2026
19 checks passed
@nschimme
nschimme deleted the fix-glsl-shader-locale-compilation-bug-17562491324332354441 branch September 14, 2026 15:37
@codecov

codecov Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.91304% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 27.27%. Comparing base (6306cfd) to head (9199337).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/opengl/legacy/ShaderUtils.cpp 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #557      +/-   ##
==========================================
+ Coverage   27.24%   27.27%   +0.02%     
==========================================
  Files         559      559              
  Lines       45893    45912      +19     
  Branches     4879     4879              
==========================================
+ Hits        12505    12522      +17     
- Misses      33388    33390       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shader compile error crashes MMapper 26.x on Intel HD 4000 / Mesa (GL 4.2)

1 participant