Yellow-Dog-Man / Resonite-Issues

Issue repository for Resonite.
https://resonite.com
140 stars 2 forks source link

Memory leak on malformed/old font import #3199

Open jae1911 opened 2 days ago

jae1911 commented 2 days ago

Describe the bug?

When importing certain malformed/old fonts, it will cause a memory leak which will slowly consume all the RAM available on the computer.

To Reproduce

For testing, this font file is provided (from https://www.bok.net/MonteCarlo/, Generic TrueType .TTF files (Medium and Bold in a zip file) contributed by Christian Neukirchen):

MonteCarloBold.zip

Steps:

  1. Load font into Resonite
  2. Observe the font is not appearing in-game
  3. Observe in the debug menu a stuck task
  4. Close the current world
  5. Observe in the debug menu the stuck task remains
  6. Observe in the task manager the memory usage of Resonite keeps going up

Expected behavior

The font should either be imported or fail to import without filling up the user's ram.

Screenshots

The stuck task:

Image

Memory usage after some time (world in which the import was done closed):

Image

Resonite Version Number

Beta 2024.11.19.479

What Platforms does this occur on?

Windows

What headset if any do you use?

Quest Pro, Desktop

Log Files

TETHYS - 2024.11.19.479 - 2024-11-20 00_47_29.log

Additional Context

Originally was a security ticket that I was told to port here. Didn't have time and forgot to port it here.

Reporters

U-j4 | j4.lc (Discord)

stiefeljackal commented 2 days ago

There is currently an issue with how FrooxEngine performs the glyph atlas allocation where it leads to this extreme memory consumption. I have noted my investigational findings in #88 and #2771 as those issues exhibit the same memory consumption behavior and lead to this problem.

Frooxius commented 2 days ago

Thanks for the relevant info and investigating! I'll try to look at this soon.

Do you have an idea on how often this occurs in practice? I wonder how much is this responsible for high memory usage that people are casually reporting. It's hard to tell if this and the linked issues are culprit or not.

stiefeljackal commented 2 days ago

Do you have an idea on how often this occurs in practice? I wonder how much is this responsible for high memory usage that people are casually reporting. It's hard to tell if this and the linked issues are culprit or not.

More than likely it does not occur often in practice. If someone triggered this occurrence, it should cause the RAM to spike up quickly since the while loop does not terminate when it continues to allocate the glyphs. As far as the glyph allocation in general being the culprit of the high memory usage, I am unsure on that. In my video in #88, I do see that the same font file having its glyphs fully packed a few times, but I am unsure if it is due to variants of that same font file.