From 4c51c1a0355af54681fd78572d754f54ff46b94c Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Wed, 10 Jun 2026 21:43:18 +0100 Subject: [PATCH] Stop rebinding --- .../graphics-library/universal-rendering-context.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/graphics/graphics-library/universal-rendering-context.ts b/src/graphics/graphics-library/universal-rendering-context.ts index 7cc8971..2a94882 100644 --- a/src/graphics/graphics-library/universal-rendering-context.ts +++ b/src/graphics/graphics-library/universal-rendering-context.ts @@ -64,8 +64,10 @@ export const getUniversalRenderingContext = ( }; canvas.addEventListener('webglcontextlost', handleContextLost, false); + const boundFunctions = new Map(); + const contextLostHandler = { - get: function (target: UniversalRenderingContext, prop: string) { + get: function (target: UniversalRenderingContext, prop: string | symbol) { const value = (target as any)[prop]; if (typeof value === 'function') { @@ -74,7 +76,13 @@ export const getUniversalRenderingContext = ( throw new ContextLostException(); } - return value.bind(target); + let bound = boundFunctions.get(prop); + if (bound === undefined) { + bound = value.bind(target); + boundFunctions.set(prop, bound); + } + + return bound; } return value;