BitmapFont bug [FIXED] in RENDER_BLIT mode

I have found a bug in the BitmapFont library:
in BitmapTextField.updateGraphic it distinguishes between RENDER_BLIT and !RENDER_BLIT

#if (RENDER_BLIT)
if (_bitmapData == null || (_fieldWidth != _bitmapData.width || _fieldHeight != _bitmapData.height))
{
	if (_bitmapData != null)
	{
		_bitmapData.dispose();
	}
	
	_bitmapData = new BitmapData(_fieldWidth, _fieldHeight, true, colorForFill);
	_bitmap.bitmapData = _bitmapData;
	_bitmap.smoothing = smoothing;
}
else 
{
	_bitmapData.fillRect(_bitmapData.rect, colorForFill);
}
#else
this.graphics.clear();
...

In the case of !RENDER_BLIT it always clears graphics: if I have reached updateGraphic it means I already know that the text is sufficiently different from the previous one to redraw all, so clearing graphics is correct, but… in RENDER_BLIT it adds a few conditions for redrawing, that in my case were not always met (“0.04” has the same size of “0.08” in pixels), leading to overlapping redraws of texts.
I think that the code can be modified like this

#if (RENDER_BLIT)
if (_bitmapData != null)
{
	_bitmapData.dispose();
}

	_bitmapData = new BitmapData(_fieldWidth, _fieldHeight, true, colorForFill);
	_bitmap.bitmapData = _bitmapData;
	_bitmap.smoothing = smoothing;
#else
this.graphics.clear();
...

It works perfect for me.

bitmapData.fillRect should be more efficient than disposing and recreating the BitmapData each time. We made fillRect changes in Lime 5.1, have you tested it? Perhaps that fixes the issue?

I tried to restore the original code, but the overlapping texts are still there

this is an animated textfield, and sometimes it skips a complete redraw of it, leaving the previous number in the bitmap.

Does this happen on all platforms? If it’s HTML5, does canvas behave differently than WebGL?

It happens when it goes with the “else”:

_bitmapData.fillRect(_bitmapData.rect, colorForFill);

does not clear/refresh the bitmapData.

My only target is HTML5, and I use canvas because webGL has problems with masks.
WebGL is ok, the overlapping texts do not show up: maybe a bug in canvas fillRect (maybe an issue with transparencies)?

I’ll take a look, thanks :smile:

Any news? I have updated the libs today and read the changelog, but couldn’t find anything new about it.

We have made improvements to fillRect in recent releases, it may have been in the Lime change log

I restored the original code but the problem is still here… well, it looks even more frequent.

Is there any chance that you using latest Chrome? If yes - what about different browsers (eg. Firefox)?

You mean it could be a problem of the latest Chrome? I will give FF a try.

Yep, there is a small chance. In OpenFL slack chat we discussing about similar problem.

Can you post results?

CORS problems with FF, trying to fix them…

Hello gents,

Resurrecting this thread from its slumber, but the bitmapFont libraries on github are fairly old and use tilesheets. I was wondering if @GiG, your updated/fixed library is up somewhere?

Hello,

I do have an updated version here : GitHub - MatseFR/BitmapFont: cross-platform bitmap font implementation
It’s quite old now but uses TileMap, I haven’t used it lately : let me know if there are issues and I’ll try to fix them