Babylon.js: GUI TextBlock appears to have issues when resizeToFit and padding are set

Created on 6 Aug 2020  路  3Comments  路  Source: BabylonJS/Babylon.js

Repro playground: https://www.babylonjs-playground.com/#XCPP9Y#3380

As you can see in the playground, the text on the GUI updates every second, causing a width change due to resizeToFit being true. However, fragments of the background remain rendered where they were at the previous width. Oddly, this appears not to repro if I don't set left or right padding on the TextBlock.

bug gui

All 3 comments

Ok, I don't understand how to fix this one, will need the master of GUI @Deltakosh :)

Here's a simpler repro:

https://www.babylonjs-playground.com/#XCPP9Y#3444

The bug happens only when setting a right padding: when switching to a smaller text, the cleared rectangle is not wide enough to encompass the right padding, so this part is not cleared.

The problem comes from the ADT _invalidatedRectangle not being wide enough: if disabling the invalidate rect mechanism by setting ADT.useInvalidateRectOptimization = false the problem does not show up (as the full texture is cleared).

I guess it has something to do with _prevCurrentMeasureTransformedIntoGlobalSpace not being ok but I don't see how to make it ok...

There are two possible workarounds, but neither are really satisfactory I think:

  • set ADT.useInvalidateRectOptimization = false
  • or do:
textBlock.text = 'short';
advancedTexture.markAsDirty();
advancedTexture.rootContainer._markAsDirty();

The last two lines will force a redraw of the texture, and because ADT._invalidatedRectangle = null at that time, a full clearing of the texture will be done.

ok now it makes sense

Thanks a lot @Popov72

So the rect optimization has some limitations and this is one of them so the recommended fix is to cancel the optimization with ADT.useInvalidateRectOptimization = false

Thanks a lot @Popov72

Actually I found a way to get the invalidateMeasure to work. Should be fixed asap

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Exolun picture Exolun  路  3Comments

CadsoftBrianW picture CadsoftBrianW  路  3Comments

phuein picture phuein  路  3Comments

emackey picture emackey  路  5Comments

schiette picture schiette  路  5Comments