Open JackTheFoxOtter opened 2 months ago
Additional info: I did this on my (.Net 8.0) headless, which appears unaffected, it only memory leaked my client.
Duplicate of #88
Kind of, but they might be related. #88 describes memory allocation issues for the StaticFont
, this one is for the DynamicSpriteFont
.
Also for whatever reason I can't comment / upvote #88, looks like the issue is bugged (?)
Kind of, but they might be related. #88 describes memory allocation issues for the
StaticFont
, this one is for theDynamicSpriteFont
.
Related, yes. However, they do follow the same logic as far as how the engine handles its font allocation.
These are sufficiently different implementations that the underlying cause can be very different.
Let's keep both open for now.
An additional investigation into this issue has pinpointed the cause of the excessive memory allocation to continuously occur in the method PackGlyphs
in FrooxEngine.Font
. To preface, this is in no way suggesting that this method needs to be fixed as outside parameters might need to be addressed as well. This purpose of his post is to provide the source of the memory issue and a possible lead to addressing the issue.
PackGlyphs
utilizes a while
loop to assist in the glyph atlas allocation. This loop somehow never terminates when MaxSize
is set to certain values as described in this issue. Additionally, it appears that this issue may only occur for certain textures. To demonstrate this, an experiment was conducted and recorded. Within this experiment, two mods were used to help provide diagnostic information: !Console is used for logging mod output and Jworkz.ResoniteRandoFixes is used for simply printing the start and end of the PackGlyphs
method call.
Please pardon the quality of the video as GitHub limits these to only 10 MB max, and this experiment lasted slightly longer. I do have the original video that can be sent upon request.
https://github.com/user-attachments/assets/4a1bc1e3-f7cf-4f61-bee5-f5f0de049ba3
Before recording, the following items were setup:
TextRenderer
.DynamicSpriteFont
component was added to the slot. It contains two entries to parse the names "A" and "B" to the default particle sprite texture.FontCollection
component was added to the slot. The 0th position is the default FontChain
on Root and the 1st position is the DynamicSpriteFont
component from above.TextRenderer
's material utilizes the FontCollection
component from above. In the video, the following occurs in this order:
MaxSize
for DynamicSpriteFont
is set to 512.DynamicSpriteFont
do not show the asset URL and instead displays an empty string (i.e., "Done packing glyphs for !" and "Packing Glyphas for . Entering While loop.").MaxSize
for DynamicSpriteFont
is set to 777.Dynamic SpriteFont
entries, "A" and "B" being those entries.This behavior was also witnessed in another investigation that was conducted for #88. Although both components (StaticFont
and DynamicSpriteFont
) utilize sufficiently different implementations, they both utilize FrooxEngine.Font
and the underlying PackGlyphs
method and they both exhibit the same excessive memory allocation behavior that never ends when a sizing property is altered. This is just merely a conclusion after conducting the experiment above and the one in #88.
Describe the bug?
When you change the size of a DynamicSpriteFont, it seems to cause a memory leak once a glyph with the new size is being loaded.
To Reproduce
Setup a DynamicSpriteFont, create a text that displays a sprite from it, change the resolution (I increased it from 256 to 512), and force it to load a new sprite.
Expected behavior
No memory leak!
Screenshots
https://github.com/user-attachments/assets/937856f9-63c9-4eff-8af2-60ccc674ca35
Resonite Version Number
Beta 2024.8.5.1341
What Platforms does this occur on?
Windows
What headset if any do you use?
Valve Index
Log Files
J4-C - 2024.8.5.1341 - 2024-08-16 16_56_33.log
Additional Context
No response
Reporters
No response