[PR #2948] [MERGED] Fix the crash on every start with HDR on in macOS, and start with HDR off after a start that dies in it #4701

Closed
opened 2026-11-03 05:07:18 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/2948
Author: @kacpherek
Created: 10/27/2026
Status: ✅ Merged
Merged: 10/28/2026
Merged by: @ludovic111

Base: main ← Head: fix/hdr-crash-macos


📝 Commits (2)

  • b8f0cde Fix the Metal HDR colour space lookup that crashed macOS at start
  • dddcc99 Start with HDR off after a start that died switching it on

📊 Changes

5 files changed (+42 additions, -7 deletions)

View changed files

📝 Cargo.toml (+4 -2)
📝 crates/horizon-client/src/game/options.rs (+1 -0)
📝 crates/horizon-client/src/gfx.rs (+19 -1)
📝 crates/horizon-client/src/graphics.rs (+13 -2)
📝 third_party/wgpu-hal/src/metal/surface.rs (+5 -2)

📄 Description

What and why

Turning on HDR on a Mac crashed the game, and every later start crashed too, because the setting is kept in horizon-graphics.txt. The log ends after the audio line with no panic, because the process dies in a native fault.

  • Metal HDR colour space lookup (wgpu-hal, our vendored copy). HDR10 (Rgb10a2Unorm + PQ) is what Horizon picks on every Mac. To set a PQ layer the Metal backend resolves kCGColorSpaceITUR_2100_PQ from CoreGraphics at run time. The global holds a CFStringRef, and dlsym returns the address of that global, but the code read the address itself as the string. CGColorSpaceCreateWithName was then handed a pointer to a pointer and faulted (checked with a few lines of C: the address as a name exits with SIGBUS, the value read through the pointer works). The code now reads through the pointer. The same lookup serves Extended Display P3 and HLG. scRGB and plain sRGB never used it.
  • Safety net. Before HDR output is switched on, the renderer writes horizon-hdr-pending next to options.txt and removes it once the first HDR frame is presented. If the next start finds the file, it turns hdr off in horizon-graphics.txt, logs why, and deletes the file. Any failure that kills the game in HDR (not only this one) therefore costs one crash, not every start.

Vanilla reference

Not a vanilla behaviour: HDR output is a Horizon setting.

Self-check

clippy passes for horizon-client. fmt checked. Not run in game (the reproduction was the C check of the symbol lookup above, on an Apple Silicon Mac).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/2948 **Author:** [@kacpherek](https://github.com/kacpherek) **Created:** 10/27/2026 **Status:** ✅ Merged **Merged:** 10/28/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/hdr-crash-macos` --- ### 📝 Commits (2) - [`b8f0cde`](https://github.com/horizon-rust/horizon/commit/b8f0cde9004d8067c8b11a048efecc3ad4698871) Fix the Metal HDR colour space lookup that crashed macOS at start - [`dddcc99`](https://github.com/horizon-rust/horizon/commit/dddcc9972687042a6aa9a3ad79dbf65b3a09c086) Start with HDR off after a start that died switching it on ### 📊 Changes **5 files changed** (+42 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.toml` (+4 -2) 📝 `crates/horizon-client/src/game/options.rs` (+1 -0) 📝 `crates/horizon-client/src/gfx.rs` (+19 -1) 📝 `crates/horizon-client/src/graphics.rs` (+13 -2) 📝 `third_party/wgpu-hal/src/metal/surface.rs` (+5 -2) </details> ### 📄 Description ## What and why Turning on HDR on a Mac crashed the game, and every later start crashed too, because the setting is kept in `horizon-graphics.txt`. The log ends after the audio line with no panic, because the process dies in a native fault. - Metal HDR colour space lookup (wgpu-hal, our vendored copy). HDR10 (`Rgb10a2Unorm` + PQ) is what Horizon picks on every Mac. To set a PQ layer the Metal backend resolves `kCGColorSpaceITUR_2100_PQ` from CoreGraphics at run time. The global holds a `CFStringRef`, and `dlsym` returns the address of that global, but the code read the address itself as the string. `CGColorSpaceCreateWithName` was then handed a pointer to a pointer and faulted (checked with a few lines of C: the address as a name exits with SIGBUS, the value read through the pointer works). The code now reads through the pointer. The same lookup serves Extended Display P3 and HLG. scRGB and plain sRGB never used it. - Safety net. Before HDR output is switched on, the renderer writes `horizon-hdr-pending` next to `options.txt` and removes it once the first HDR frame is presented. If the next start finds the file, it turns `hdr` off in `horizon-graphics.txt`, logs why, and deletes the file. Any failure that kills the game in HDR (not only this one) therefore costs one crash, not every start. ## Vanilla reference Not a vanilla behaviour: HDR output is a Horizon setting. ## Self-check clippy passes for horizon-client. fmt checked. Not run in game (the reproduction was the C check of the symbol lookup above, on an Apple Silicon Mac). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:07:18 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#4701
No description provided.