mirror of
https://github.com/Heretek-AI/GDevelop-Heretek.git
synced 2026-10-12 02:02:42 +00:00
Fix crash when using invalid BBCode color values in BBText (#8386)
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user