[BUG] Font rendering issue on iphone
serzhiio opened this issue · comments
I have very strange issue when rendering a lot of text data on chart.
This issue appers only on mobile device (i use iphone 12 pro max), all mobile browsers affected, rendering just stops in one moment (after several seconds of working) with no errors.
It worth me a lot of time to realize this error was caused by g.draw_text((x as f32, y as f32), color, &text);
, once i comment this line everything is fine but no text is rendering anymore.
It looks like everything is happening inside font_cache::prepare_for_draw()
, but i receive no errors or panics, it just stops rendering. Looks like crash.
Process usually stops in font_cache::try_append_glyph()
fn, maybe in self.packer.try_allocate(glyph_bitmap.size)
wihtout any panics.
Sometimes it stops with panic in font_cache::draw_bitmap_at()
right in assert!()
checks.
And panic can happens in font_cache::get_renderer2d_actions()
right in let texture_entry = texture_cache.entries.get(&key).unwrap()
.
Thanks for the report! I don't have an iPhone for testing, but it's possible that we're hitting a GPU memory limit.
Sometimes it stops with panic in font_cache::draw_bitmap_at() right in assert!() checks.
Could you give me the full panic logs/traces please, and also the assert message that you get?
I will try to collect some. It is very difficult to get logs from iphone.
Most of time i have no visible error.
First two stack traces are most common
Any ideas how to fix it? Or maybe to investigate deeper?
My workload is a lot of numbers rendered each frame. So it seems better to pre-load all digits into one texture and then just use this texture for all needs without changing anything.
Thank you for the logs! I'll look in more detail soon, but it seems like something must be going wrong earlier in the execution (probably a memory allocation failure), as the calculations involving line_size_bytes
/etc don't make any sense. Are you getting any errors before that point?
Does the issue go away if you reduce GlyphCacheTexture::SIZE
, for example to 256
instead of 1024
?
So it seems better to pre-load all digits into one texture and then just use this texture for all needs without changing anything.
It should be possible to do this using the Graphics2D::capture()
API to screenshot the text, followed by create_image_from_raw_pixels()
to create a texture. You could save this as a pre-generated sprite sheet if you like.
(however you would lose the subpixel kerning that Speedy2D performs)
Does the issue go away if you reduce GlyphCacheTexture::SIZE, for example to 256 instead of 1024?
I tried to make it lower/bigger, nothing changes
It definitley looks like UB or some memory issue, but since it is iphone it makes it hard to diagnose