You've already forked Nitro_Render_V3
mirror of
https://github.com/duckietm/Nitro_Render_V3.git
synced 2026-06-19 15:06:20 +00:00
🆙 Patch GlTextureSystem & Fix effects like BBRed
- Monkey-patch the renderer's GlTextureSystem to prevent crashes from destroyed textures
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user