From 4f6a1ec2364bb7d85f1c6f9907b5b15c5f4e14c0 Mon Sep 17 00:00:00 2001 From: huaxiabuluo Date: Wed, 13 May 2026 12:26:16 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E5=BB=B6=E8=BF=9F=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E5=AE=9D=20canvas=20=E9=A6=96=E5=B8=A7=E6=B8=B2=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/f-my/src/index.tsx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/f-my/src/index.tsx b/packages/f-my/src/index.tsx index c0fe90e5..74b89a8b 100644 --- a/packages/f-my/src/index.tsx +++ b/packages/f-my/src/index.tsx @@ -52,6 +52,7 @@ Component({ this.setCanvasId(); }, didMount() { + this.destroyed = false; if (!isAppX2CanvasEnv()) { console.error('当前基础库版本过低,请升级基础库版本到 2.7.0 或以上。'); } @@ -75,6 +76,11 @@ Component({ }); }, didUnmount() { + this.destroyed = true; + if (this.renderFrameId != null) { + this.nativeCanvas?.cancelAnimationFrame(this.renderFrameId); + this.renderFrameId = null; + } const { canvas } = this; if (!canvas) return; canvas.destroy(); @@ -105,6 +111,7 @@ Component({ } const { width, height } = canvas; + this.nativeCanvas = canvas; const pixelRatio = Math.ceil(getPixelRatio()); @@ -115,6 +122,9 @@ Component({ height: height * pixelRatio, }, () => { + if (this.destroyed) { + return; + } const context = canvas.getContext('2d'); const fCanvas = this.createCanvas({ width, @@ -125,8 +135,14 @@ Component({ requestAnimationFrame: canvas.requestAnimationFrame.bind(canvas), cancelAnimationFrame: canvas.cancelAnimationFrame.bind(canvas), }); - fCanvas.render().catch((error) => { - this.catchError(error); + this.renderFrameId = canvas.requestAnimationFrame(() => { + this.renderFrameId = null; + if (this.destroyed) { + return; + } + fCanvas.render().catch((error) => { + this.catchError(error); + }); }); }, ); From 7101beeefb0acc264f9898408f9af4520bce053c Mon Sep 17 00:00:00 2001 From: Bruce Date: Wed, 13 May 2026 12:43:32 +0800 Subject: [PATCH 2/3] Update packages/f-my/src/index.tsx Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- packages/f-my/src/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/f-my/src/index.tsx b/packages/f-my/src/index.tsx index 74b89a8b..03413e3b 100644 --- a/packages/f-my/src/index.tsx +++ b/packages/f-my/src/index.tsx @@ -81,6 +81,7 @@ Component({ this.nativeCanvas?.cancelAnimationFrame(this.renderFrameId); this.renderFrameId = null; } + this.nativeCanvas = null; const { canvas } = this; if (!canvas) return; canvas.destroy(); From d855bc5e22f0181d2cebac2cc3f26f3ea64e3509 Mon Sep 17 00:00:00 2001 From: Bruce Date: Wed, 13 May 2026 12:43:42 +0800 Subject: [PATCH 3/3] Update packages/f-my/src/index.tsx Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- packages/f-my/src/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/f-my/src/index.tsx b/packages/f-my/src/index.tsx index 03413e3b..75ca6e0e 100644 --- a/packages/f-my/src/index.tsx +++ b/packages/f-my/src/index.tsx @@ -112,6 +112,7 @@ Component({ } const { width, height } = canvas; + if (this.destroyed) return; this.nativeCanvas = canvas; const pixelRatio = Math.ceil(getPixelRatio());