@@ -7,6 +7,7 @@ import { findAvailableLocale } from '../i18n/utils.js';
7
7
8
8
import { ABSOLUTE_URL } from './constants.js' ;
9
9
import { AssetVariants } from './asset-variants.js' ;
10
+ import { getApplication } from '../framework/globals.js' ;
10
11
11
12
// auto incrementing number for asset ids
12
13
var assetIdCounter = - 1 ;
@@ -192,29 +193,30 @@ class Asset extends EventHandler {
192
193
return null ;
193
194
194
195
if ( this . type === 'texture' || this . type === 'textureatlas' || this . type === 'bundle' ) {
195
- var app = this . registry . _loader . _app ;
196
- var device = app . graphicsDevice ;
197
-
198
- for ( var i = 0 , len = VARIANT_DEFAULT_PRIORITY . length ; i < len ; i ++ ) {
199
- var variant = VARIANT_DEFAULT_PRIORITY [ i ] ;
200
- // if the device supports the variant
201
- if ( ! device [ VARIANT_SUPPORT [ variant ] ] ) continue ;
202
-
203
- // if the variant exists in the asset then just return it
204
- if ( this . file . variants [ variant ] ) {
205
- return this . file . variants [ variant ] ;
206
- }
207
-
208
- // if the variant does not exist but the asset is in a bundle
209
- // and the bundle contain assets with this variant then return the default
210
- // file for the asset
211
- if ( app . enableBundles ) {
212
- var bundles = app . bundles . listBundlesForAsset ( this ) ;
213
- if ( ! bundles ) continue ;
196
+ var app = this . registry ?. _loader ?. _app || getApplication ( ) ;
197
+ var device = app ?. graphicsDevice ;
198
+ if ( device ) {
199
+ for ( var i = 0 , len = VARIANT_DEFAULT_PRIORITY . length ; i < len ; i ++ ) {
200
+ var variant = VARIANT_DEFAULT_PRIORITY [ i ] ;
201
+ // if the device supports the variant
202
+ if ( ! device [ VARIANT_SUPPORT [ variant ] ] ) continue ;
203
+
204
+ // if the variant exists in the asset then just return it
205
+ if ( this . file . variants [ variant ] ) {
206
+ return this . file . variants [ variant ] ;
207
+ }
214
208
215
- for ( var j = 0 , len2 = bundles . length ; j < len2 ; j ++ ) {
216
- if ( bundles [ j ] . file && bundles [ j ] . file . variants && bundles [ j ] . file . variants [ variant ] ) {
217
- return this . file ;
209
+ // if the variant does not exist but the asset is in a bundle
210
+ // and the bundle contain assets with this variant then return the default
211
+ // file for the asset
212
+ if ( app . enableBundles ) {
213
+ var bundles = app . bundles . listBundlesForAsset ( this ) ;
214
+ if ( ! bundles ) continue ;
215
+
216
+ for ( var j = 0 , len2 = bundles . length ; j < len2 ; j ++ ) {
217
+ if ( bundles [ j ] . file && bundles [ j ] . file . variants && bundles [ j ] . file . variants [ variant ] ) {
218
+ return this . file ;
219
+ }
218
220
}
219
221
}
220
222
}
0 commit comments