Skip to content

Commit

Permalink
chore: cleanup manager lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Oct 21, 2023
1 parent b93242e commit 248b895
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions packages/fiber/src/native/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ export function polyfills() {
THREE.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
if (this.path && typeof url === 'string') url = this.path + url

this.manager.itemStart(url)

const texture = new THREE.Texture()

getAsset(url)
Expand All @@ -145,7 +147,13 @@ export function polyfills() {

onLoad?.(texture)
})
.catch(onError)
.catch((error) => {
onError?.(error)
this.manager.itemError(url)
})
.finally(() => {
this.manager.itemEnd(url)
})

return texture
}
Expand All @@ -154,20 +162,19 @@ export function polyfills() {
THREE.FileLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
if (this.path && typeof url === 'string') url = this.path + url

this.manager.itemStart(url)

getAsset(url)
.then(async (uri) => {
this.manager.itemStart(url)

const base64 = await fs.readAsStringAsync(uri, { encoding: fs.EncodingType.Base64 })
const data = Buffer.from(base64, 'base64')
onLoad?.(data.buffer)

this.manager.itemEnd(url)
})
.catch((error) => {
onError?.(error)

this.manager.itemError(url)
})
.finally(() => {
this.manager.itemEnd(url)
})
}
Expand Down

0 comments on commit 248b895

Please sign in to comment.