Skip to content

Conversation

@TKanX
Copy link
Member

@TKanX TKanX commented Jul 23, 2025

Summary:

Fixed a critical issue where the renderer could crash if a new texture pack failed to load during a call to updateTextures. The previous implementation modified the live AssetsManager instance, which could lead to an inconsistent state if the new assets were invalid or unreachable.

Refactors the updateTextures method to use a "preload-and-swap" strategy. It now creates a temporary AssetsManager instance to load the new textures in the background. Only after the new assets are successfully loaded is the main AssetsManager instance replaced. This ensures that the renderer remains in a stable state and does not crash if a texture update fails.

Changes:

  • Refactored updateTextures for Safe Asset Loading:
    • The updateTextures method in renderer.js no longer modifies the active AssetsManager directly.
    • It now instantiates a temporary AssetsManager to handle the loading of the new texture index and atlas.
    • If the temporary manager successfully loads the new assets, the renderer's primary _assetsManager is swapped with the temporary one.
    • If any part of the loading process fails within the temporary instance, an error is thrown, and the original, stable _assetsManager remains untouched, preventing a renderer crash.
  • Improved Error Handling:
    • Simplified the try...catch block and error propagation, making the method more robust.
  • Forced Re-render:
    • After a successful texture update and swap, a full, forced re-render of all layers is now triggered by calling this._layersManager.render(true) to immediately reflect the new textures.

@TKanX TKanX self-assigned this Jul 23, 2025
Copilot AI review requested due to automatic review settings July 23, 2025 15:42
@TKanX TKanX added the bug 🐛 Something isn't working label Jul 23, 2025
@TKanX TKanX linked an issue Jul 23, 2025 that may be closed by this pull request
5 tasks

This comment was marked as outdated.

@TKanX TKanX requested a review from Copilot July 23, 2025 18:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a critical issue in the renderer where texture pack updates could cause crashes if new assets failed to load. The solution implements a "preload-and-swap" strategy to ensure the renderer maintains a stable state during texture updates.

  • Implements safe asset loading by creating temporary instances before swapping
  • Moves frameRequested initialization to constructor for better state management
  • Improves error handling to prevent renderer crashes during failed texture updates
Comments suppressed due to low confidence (1)

src/renderer.js:305

  • [nitpick] The variable name 'tempTextures' could be more descriptive. Consider renaming it to 'newTexturePack' or 'candidateTextures' to better reflect that this represents the new texture pack being validated before swapping.
      const tempTextures = new TexturePack(

@TKanX TKanX merged commit e17d477 into main Jul 23, 2025
8 checks passed
@TKanX TKanX deleted the bugfix/50-renderer-crashes-when-updating-texture-packs-due-to-race-condition branch July 23, 2025 18:45
@TKanX TKanX changed the title fix(renderer): Fix the error of not being able to update texture packs fix(renderer): Prevent Renderer Crash on Texture Update by Preloading Assets Jul 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐛 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Renderer Crashes When Updating Texture Packs Due to Race Condition

2 participants