[PR #3994] [MERGED] Applying a resource pack no longer freezes the window #5342

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/3994
Author: @d3grando
Created: 10/29/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @levzzz5154

Base: main ← Head: fix-2740


📝 Commits (2)

  • 5aa2da4 Applying a resource pack no longer freezes the window
  • 03ba766 Merge origin/main into fix-2740

📊 Changes

3 files changed (+225 additions, -126 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+9 -5)
📝 crates/horizon-client/src/game/packs.rs (+202 -35)
📝 crates/horizon-client/src/game/server_packs.rs (+14 -86)

📄 Description

🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando themselves.

What and why

Applying a resource pack froze the game. reload_packs (the pack screen's Done, F3+T, options-set resourcePacks) called reload_selected_packs, which ran the whole CPU half of the reload on the render thread: the overlay root, the block and item models, the atlases, the pack tables and the mip chains. The window drew nothing and handled no input until it finished. With a 64x pack that took 8 seconds on a 9800X3D. On a slower PC it takes longer, and Windows marks the window "Not responding", which is how players end up killing the game.

Server packs already did this the right way. Their reload is staged on a worker under the progress overlay, then applied on the render thread (PackReload, drive_pack_reload). This PR moves the player's own reload onto that same path:

  • PackReload moves to game/packs.rs and stays the only reload in flight, as Game::pack_reload. It records who asked for it (ReloadKind::Selection or Server), and the outcome goes back to that caller. A failed selection reload still opens the pack screen with the error. A failed server reload still goes to ServerPacks::reloaded (the recovery reload).
  • spawn_pack_reload is the one place a reload starts. It releases held keys and stages on a pack-reload thread.
  • A reload asked for while another one is running waits for it (pending_pack_reload, which already handled "world resources not ready yet"). While a selection reload runs, the server packs' tick waits too, so neither reload replaces the other.
  • reload_selected_packs and stage_selected_packs, the synchronous path, are removed.

This fixes the freeze. The attached log has no panic. The zip allocation crash fixed in #2815 was already in v0.2.97, so the crash and the freeze seem to be the same thing: a window that stopped responding.

Fixes #2740

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

Read with javap on the 26.3 client jar:

  • Minecraft.reloadResourcePacks(boolean, GameLoadCookie) returns pendingReload when a LoadingOverlay is already up. Otherwise it starts ReloadableResourceManager.createReload on Util.backgroundExecutor().forName("resourceLoad") and sets a LoadingOverlay over it. It never loads on the render thread.
  • Minecraft.runTick starts the pending reload once the overlay is gone. Here that is pending_pack_reload.
  • LoadingOverlay.tick calls onFinish once ReloadInstance.isDone(). Here that is drive_pack_reload.

No parity harness covers resource reloading. The unit tests in game::packs::tests check the threading and the queueing.

Self-check

tools/pr_ready.py doesn't run on Windows (it needs SIGHUP), so I ran its steps by hand:

  • cargo fmt --all -- --check: clean
  • cargo clippy -p horizon-client --all-targets -- -D warnings: clean
  • cargo build --profile fast -p horizon-client --bins: no warnings
  • cargo test --profile fast -p horizon-client --bin horizon-client -- packs::tests server_packs::tests: 7 passed, 0 failed
    • a_reload_stages_on_a_worker_while_the_caller_goes_on: the stage blocks until the test releases it, so spawn returning at all shows the caller is free. It also checks the progress lines, that the stage runs on the pack-reload thread, and that the outcome is taken once.
    • a_panicking_stage_fails_the_reload: a panic in the worker comes back as an error, not a crash.
    • a_reload_waits_for_world_resources_and_the_one_in_flight: a reload asked for while another one runs, or before the world's resources exist, waits.
  • Before the fix (the code in game.rs, game/packs.rs and game/server_packs.rs reverted, the tests kept): the test build fails with 13 errors. PackReload, ReloadKind and reload_waits don't exist on main, so main cannot stage a selection reload off the render thread.

In game, single player on its server thread (Windows 11, RTX 5080). I used a synthetic 64x pack: every block, item and entity texture of the 26.3 jar scaled 4x, 2874 textures. During bench 25, I timed options-set resourcePacks ["vanilla","file/big64.zip"] and polled state meanwhile:

main this PR
options-set reply 8069 ms 29 ms
longest state reply during the reload 7917 ms 43 ms
worst frame (max_ms) 8011 ms 746 ms (the render-thread apply, as for server packs)

With the fix, the progress overlay ("Preparing resources", then "Loading assets") draws during the reload and the window keeps responding. Afterwards the pack is applied: a second pack with recoloured block textures shows in the world. A reload from the title screen (back to vanilla) works the same way.

Not tested here: a server pushing a pack. That path now goes through the same spawn_pack_reload and drive_pack_reload, with the same steps as before.

Screenshots

after: the loading overlay's progress bar draws over the world while the 64x pack loads

On main, the window freezes on its last frame for the whole reload, about 8 seconds with a 64x pack. With this PR, the loading overlay's progress bar draws over the frame, then the world comes back with the new pack's textures.

🤖 Generated with Claude Code


🔄 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/3994 **Author:** [@d3grando](https://github.com/d3grando) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `fix-2740` --- ### 📝 Commits (2) - [`5aa2da4`](https://github.com/horizon-rust/horizon/commit/5aa2da49608f64dc9f56ed32345cecd06db59cbc) Applying a resource pack no longer freezes the window - [`03ba766`](https://github.com/horizon-rust/horizon/commit/03ba7662d5708d4646eb96f535cd3215f1a1999c) Merge origin/main into fix-2740 ### 📊 Changes **3 files changed** (+225 additions, -126 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+9 -5) 📝 `crates/horizon-client/src/game/packs.rs` (+202 -35) 📝 `crates/horizon-client/src/game/server_packs.rs` (+14 -86) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando themselves. ## What and why Applying a resource pack froze the game. `reload_packs` (the pack screen's Done, F3+T, `options-set resourcePacks`) called `reload_selected_packs`, which ran the whole CPU half of the reload on the render thread: the overlay root, the block and item models, the atlases, the pack tables and the mip chains. The window drew nothing and handled no input until it finished. With a 64x pack that took 8 seconds on a 9800X3D. On a slower PC it takes longer, and Windows marks the window "Not responding", which is how players end up killing the game. Server packs already did this the right way. Their reload is staged on a worker under the progress overlay, then applied on the render thread (`PackReload`, `drive_pack_reload`). This PR moves the player's own reload onto that same path: - `PackReload` moves to `game/packs.rs` and stays the only reload in flight, as `Game::pack_reload`. It records who asked for it (`ReloadKind::Selection` or `Server`), and the outcome goes back to that caller. A failed selection reload still opens the pack screen with the error. A failed server reload still goes to `ServerPacks::reloaded` (the recovery reload). - `spawn_pack_reload` is the one place a reload starts. It releases held keys and stages on a `pack-reload` thread. - A reload asked for while another one is running waits for it (`pending_pack_reload`, which already handled "world resources not ready yet"). While a selection reload runs, the server packs' tick waits too, so neither reload replaces the other. - `reload_selected_packs` and `stage_selected_packs`, the synchronous path, are removed. This fixes the freeze. The attached log has no panic. The zip allocation crash fixed in #2815 was already in v0.2.97, so the crash and the freeze seem to be the same thing: a window that stopped responding. Fixes #2740 ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [x] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference Read with javap on the 26.3 client jar: - `Minecraft.reloadResourcePacks(boolean, GameLoadCookie)` returns `pendingReload` when a `LoadingOverlay` is already up. Otherwise it starts `ReloadableResourceManager.createReload` on `Util.backgroundExecutor().forName("resourceLoad")` and sets a `LoadingOverlay` over it. It never loads on the render thread. - `Minecraft.runTick` starts the pending reload once the overlay is gone. Here that is `pending_pack_reload`. - `LoadingOverlay.tick` calls `onFinish` once `ReloadInstance.isDone()`. Here that is `drive_pack_reload`. No parity harness covers resource reloading. The unit tests in `game::packs::tests` check the threading and the queueing. ## Self-check `tools/pr_ready.py` doesn't run on Windows (it needs SIGHUP), so I ran its steps by hand: - `cargo fmt --all -- --check`: clean - `cargo clippy -p horizon-client --all-targets -- -D warnings`: clean - `cargo build --profile fast -p horizon-client --bins`: no warnings - `cargo test --profile fast -p horizon-client --bin horizon-client -- packs::tests server_packs::tests`: 7 passed, 0 failed - `a_reload_stages_on_a_worker_while_the_caller_goes_on`: the stage blocks until the test releases it, so `spawn` returning at all shows the caller is free. It also checks the progress lines, that the stage runs on the `pack-reload` thread, and that the outcome is taken once. - `a_panicking_stage_fails_the_reload`: a panic in the worker comes back as an error, not a crash. - `a_reload_waits_for_world_resources_and_the_one_in_flight`: a reload asked for while another one runs, or before the world's resources exist, waits. - Before the fix (the code in `game.rs`, `game/packs.rs` and `game/server_packs.rs` reverted, the tests kept): the test build fails with 13 errors. `PackReload`, `ReloadKind` and `reload_waits` don't exist on main, so main cannot stage a selection reload off the render thread. In game, single player on its server thread (Windows 11, RTX 5080). I used a synthetic 64x pack: every block, item and entity texture of the 26.3 jar scaled 4x, 2874 textures. During `bench 25`, I timed `options-set resourcePacks ["vanilla","file/big64.zip"]` and polled `state` meanwhile: | | main | this PR | |---|---|---| | `options-set` reply | 8069 ms | 29 ms | | longest `state` reply during the reload | 7917 ms | 43 ms | | worst frame (`max_ms`) | 8011 ms | 746 ms (the render-thread apply, as for server packs) | With the fix, the progress overlay ("Preparing resources", then "Loading assets") draws during the reload and the window keeps responding. Afterwards the pack is applied: a second pack with recoloured block textures shows in the world. A reload from the title screen (back to vanilla) works the same way. Not tested here: a server pushing a pack. That path now goes through the same `spawn_pack_reload` and `drive_pack_reload`, with the same steps as before. ## Screenshots ![after: the loading overlay's progress bar draws over the world while the 64x pack loads](https://raw.githubusercontent.com/d3grando/horizon/pr-assets/2740-1.png) On main, the window freezes on its last frame for the whole reload, about 8 seconds with a 64x pack. With this PR, the loading overlay's progress bar draws over the frame, then the world comes back with the new pack's textures. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:11:55 +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#5342
No description provided.