Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Font rendering issue on iphone #104

Open
serzhiio opened this issue Oct 10, 2023 · 12 comments
Open

[BUG] Font rendering issue on iphone #104

serzhiio opened this issue Oct 10, 2023 · 12 comments

Comments

@serzhiio
Copy link

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.

@serzhiio
Copy link
Author

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().

@QuantumBadger
Copy link
Owner

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?

@serzhiio
Copy link
Author

serzhiio commented Oct 10, 2023

I will try to collect some. It is very difficult to get logs from iphone.
Most of time i have no visible error.

@serzhiio
Copy link
Author

This is a panic from ‘texture_cache.entries.get(&key)’
IMG_5063

@serzhiio
Copy link
Author

This is just a stop with nothing:
IMG_5064

@serzhiio
Copy link
Author

Here is what happening when i multiply actual size on device_pixel_ratio:
IMG_5066

@serzhiio
Copy link
Author

First two stack traces are most common

@serzhiio
Copy link
Author

Any ideas how to fix it? Or maybe to investigate deeper?

@serzhiio
Copy link
Author

New stack trace:
IMG_5067

@serzhiio
Copy link
Author

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.

@QuantumBadger
Copy link
Owner

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)

@serzhiio
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@QuantumBadger @serzhiio and others