Make app.assets available immediately after AppBase construction#8952
Merged
Conversation
app.assets was created in init(), but the app registers itself globally (setApplication) in the constructor. Code that runs between construction and init() - such as a loading screen script via pc.script.createLoadingScreen, which calls callback(getApplication()) - therefore saw app.assets as undefined. This surfaced as a WebGL/WebGPU discrepancy: WebGL device creation resolves synchronously (microtask), so init() runs before the loading screen script, while WebGPU device creation is async, so the loading screen script runs first, in the window where app.assets did not yet exist. Create the AssetRegistry as a class field so app.assets is available right after construction on all backends. init() still applies the asset prefix and builds the bundle registry on the same instance, so early listeners are kept.
Build size reportThis PR changes the size of the minified bundles.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes a discrepancy where
app.assetswas undefined when accessed beforeAppBase#init()— e.g. from a loading screen script (pc.script.createLoadingScreen) under WebGPU but not WebGL. Reported in the follow-up comment on #8932.The app registers itself globally (via
setApplication) in its constructor, butapp.assetswas only created ininit(). WebGL's graphics device creation resolves synchronously (microtask), soinit()runs before the loading screen script executes; WebGPU's device creation is genuinely async, so the loading screen script runs first — in the window whereapp.assetsdid not yet exist.Changes:
AssetRegistryas anAppBaseclass field (assets = new AssetRegistry(this.loader)) instead of ininit(), soapp.assetsis available right after construction on all backends.init()continues to apply the asset prefix and build the bundle registry on the same instance (no re-creation, so any early listeners are preserved).Note: this only makes the registry available earlier; resource handlers are still registered in
init(), so attempting to actually load a device-dependent asset (e.g. a texture) beforeinit()returns a graceful "No resource handler" error rather than aTypeError. Adding assets to the registry for later loading works as expected.