🆙 Patch GlTextureSystem & Fix effects like BBRed

- Monkey-patch the renderer's GlTextureSystem to prevent crashes from destroyed textures
This commit is contained in:
DuckieTM
2026-02-07 19:08:39 +01:00
parent 9c43cb240e
commit 8f5a9f7188
7 changed files with 84 additions and 22 deletions
+45 -1
View File
@@ -1,13 +1,57 @@
import { AutoDetectOptions, Renderer, autoDetectRenderer } from 'pixi.js';
import { AutoDetectOptions, Renderer, Texture, autoDetectRenderer } from 'pixi.js';
let renderer: Renderer = null;
const patchGlTextureSystem = (r: Renderer): void =>
{
const textureSystem = (r as any).texture;
if(!textureSystem) return;
const proto = Object.getPrototypeOf(textureSystem);
if(!proto) return;
const origUpdateStyle = proto.updateStyle;
if(origUpdateStyle && !proto.__patchedUpdateStyle)
{
proto.updateStyle = function(source: any, firstCreation: boolean)
{
if(!source || source.destroyed || !source.style) return;
return origUpdateStyle.call(this, source, firstCreation);
};
proto.__patchedUpdateStyle = true;
}
const origBindSource = proto.bindSource;
if(origBindSource && !proto.__patchedBindSource)
{
proto.bindSource = function(source: any, location = 0)
{
if(!source || source.destroyed || !source.style)
{
source = Texture.EMPTY.source;
}
return origBindSource.call(this, source, location);
};
proto.__patchedBindSource = true;
}
};
export const PrepareRenderer = async (options: Partial<AutoDetectOptions>): Promise<Renderer> =>
{
renderer = await autoDetectRenderer(options);
renderer.events?.destroy();
patchGlTextureSystem(renderer);
return renderer;
};