Fix crash when using invalid BBCode color values in BBText (#8386)

This commit is contained in:
Florian Rival
2026-03-13 13:01:32 +01:00
committed by GitHub
parent f30e54ec29
commit 7dfd450cd3
2 changed files with 41 additions and 0 deletions
+20
View File
@@ -559,6 +559,26 @@ module.exports = {
this._pixiObject = new MultiStyleText('', bbTextStyles);
// Override updateText to catch errors from invalid color values
// in BBCode tags (e.g. [color=blues] instead of [color=blue]).
// Without this, PixiJS Color.normalize throws "Unable to convert color"
// which propagates to _renderScene and crashes the entire editor.
const originalUpdateText = this._pixiObject.updateText.bind(
this._pixiObject
);
this._pixiObject.updateText = (...args) => {
try {
originalUpdateText(...args);
} catch (error) {
console.warn(
'Error rendering BBText (invalid color or style in BBCode):',
error
);
// Mark as not dirty to prevent retrying every frame.
this._pixiObject.dirty = false;
}
};
this._pixiObject.anchor.x = 0.5;
this._pixiObject.anchor.y = 0.5;
this._pixiContainer.addChild(this._pixiObject);
@@ -1,4 +1,6 @@
namespace gdjs {
const logger = new gdjs.Logger('BBText renderer');
/**
* The PIXI.js renderer for the BBCode Text runtime object.
* @category Renderers > BBText
@@ -35,6 +37,25 @@ namespace gdjs {
align: runtimeObject._textAlign as PIXI.TextStyleAlign | undefined,
},
});
// Override updateText to catch errors from invalid color values
// in BBCode tags (e.g. [color=blues] instead of [color=blue]).
// Without this, PixiJS Color.normalize throws and crashes the game.
const originalUpdateText = this._pixiObject.updateText.bind(
this._pixiObject
);
this._pixiObject.updateText = (...args: any) => {
try {
originalUpdateText(...args);
} catch (error) {
logger.warn(
'Error rendering BBText (invalid color or style in BBCode): ' +
error
);
this._pixiObject.dirty = false;
}
};
instanceContainer
.getLayer('')
.getRenderer()