From 4f8c69a0f5c27a4f7316a28cb664343dd56168f4 Mon Sep 17 00:00:00 2001 From: wouterlucas Date: Thu, 2 Oct 2025 16:54:44 +0200 Subject: [PATCH] fix: infinite retry loops on unresolved image props --- src/core/CoreNode.ts | 10 +++++++++- src/core/textures/ImageTexture.ts | 2 +- src/core/textures/Texture.ts | 8 ++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/core/CoreNode.ts b/src/core/CoreNode.ts index b1892bd2..331bc219 100644 --- a/src/core/CoreNode.ts +++ b/src/core/CoreNode.ts @@ -1466,8 +1466,16 @@ export class CoreNode extends EventEmitter { } if (this.texture !== null) { - needsTextureOwnership = true; + // preemptive check for failed textures this will mark the current node as non-renderable + // and will prevent further checks until the texture is reloaded or retry is reset on the texture + if (this.texture.retryCount > this.texture.maxRetryCount) { + // texture has failed to load, we cannot render + this.updateTextureOwnership(false); + this.setRenderable(false); + return; + } + needsTextureOwnership = true; // we're only renderable if the texture state is loaded newIsRenderable = this.texture.state === 'loaded'; } else if ( diff --git a/src/core/textures/ImageTexture.ts b/src/core/textures/ImageTexture.ts index 49a013a8..9d7cef50 100644 --- a/src/core/textures/ImageTexture.ts +++ b/src/core/textures/ImageTexture.ts @@ -138,7 +138,7 @@ export class ImageTexture extends Texture { const resolvedProps = ImageTexture.resolveDefaults(props); super(txManager); this.props = resolvedProps; - this.maxRetryCount = props.maxRetryCount as number; + this.maxRetryCount = resolvedProps.maxRetryCount ?? 5; } hasAlphaChannel(mimeType: string) { diff --git a/src/core/textures/Texture.ts b/src/core/textures/Texture.ts index 0e06aec8..6918c789 100644 --- a/src/core/textures/Texture.ts +++ b/src/core/textures/Texture.ts @@ -162,7 +162,7 @@ export abstract class Texture extends EventEmitter { public memUsed = 0; public retryCount = 0; - public maxRetryCount: number | null = null; + public maxRetryCount: number = 5; /** * Timestamp when texture was created (for startup grace period) @@ -292,11 +292,7 @@ export abstract class Texture extends EventEmitter { } load(): void { - if (this.maxRetryCount === null && this.retryCount > 0) { - return; - } - - if (this.maxRetryCount !== null && this.retryCount > this.maxRetryCount) { + if (this.retryCount > this.maxRetryCount) { // We've exceeded the max retry count, do not attempt to load again return; }