fix(renderer): Prevent Renderer Crash on Texture Update by Preloading Assets #51
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 liveAssetsManagerinstance, which could lead to an inconsistent state if the new assets were invalid or unreachable.Refactors the
updateTexturesmethod to use a "preload-and-swap" strategy. It now creates a temporaryAssetsManagerinstance to load the new textures in the background. Only after the new assets are successfully loaded is the mainAssetsManagerinstance replaced. This ensures that the renderer remains in a stable state and does not crash if a texture update fails.Changes:
updateTexturesfor Safe Asset Loading:updateTexturesmethod inrenderer.jsno longer modifies the activeAssetsManagerdirectly.AssetsManagerto handle the loading of the new texture index and atlas._assetsManageris swapped with the temporary one._assetsManagerremains untouched, preventing a renderer crash.try...catchblock and error propagation, making the method more robust.this._layersManager.render(true)to immediately reflect the new textures.