[GH-ISSUE #5719] Custom bitmap fonts from a server resource pack stop rendering after a few minutes: the run-time glyph region (GLYPH_ROWS = 512) fills up and is never freed #1785

Closed
opened 2026-11-02 15:49:38 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @itsmyfox on GitHub (Nov 1, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/5719

Originally assigned to: @Joansitoh on GitHub.

Version: Nightly 2026-10-31 (68ac6f6). The same code is on main (c51dcda).
Server: play.foxygame.net (Paper 26.3 behind Velocity). It sends a ~105 MB server resource pack that draws its UI with custom fonts.

What happens
Right after joining, everything drawn with the pack's custom fonts is correct: the tab list frame, chest-menu backgrounds (drawn as glyphs in the container title), the sidebar and the HUD (hearts and food drawn with font glyphs). After a minute or two of play (opening a few menus, health changing), new glyphs stop appearing. They are drawn as the 5×8 missing-glyph outline, and everything after them on the line shifts: the missing glyph's advance (6) is not the real glyph's advance, and our layouts rely on exact advances and negative space advances. Menu backgrounds disappear completely; only a row of outlines shows to the left of the window. It stays broken until the renderer is rebuilt (pack reload or restart).

Expected
As in vanilla 26.3, every glyph keeps rendering for the whole session.

Steps to reproduce

  1. Join play.foxygame.net and accept the server resource pack.
  2. Open the tab list, then the profile, cases and server selector menus from the hotbar items, and play for a minute so that health and food change.
  3. The menu backgrounds, the HUD and the sidebar break as described (screenshots attached).

Cause

Suggested fix

  1. When Region::place fails, reset the region and every cached glyph that lives in it (what reset_cache does, with a new generation so cached layouts are redone), then retry once, instead of caching the missing glyph.
  2. Make the region larger (for example 2048 rows or more), or give run-time glyphs their own texture or array texture that can grow, so the glyphs of one screen always fit.
  3. Never cache the missing glyph for a character whose glyph exists but did not fit.

Moving the pack's font sheets into minecraft:font/ (so they go into the HUD atlas) does not work for us: they add up to about 900 MiB of RGBA and would overflow the 16384×16384 HUD atlas.

Image Image Image Image Image Image
Originally created by @itsmyfox on GitHub (Nov 1, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/5719 Originally assigned to: @Joansitoh on GitHub. **Version:** Nightly 2026-10-31 (68ac6f6). The same code is on `main` (c51dcda). **Server:** play.foxygame.net (Paper 26.3 behind Velocity). It sends a ~105 MB server resource pack that draws its UI with custom fonts. **What happens** Right after joining, everything drawn with the pack's custom fonts is correct: the tab list frame, chest-menu backgrounds (drawn as glyphs in the container title), the sidebar and the HUD (hearts and food drawn with font glyphs). After a minute or two of play (opening a few menus, health changing), new glyphs stop appearing. They are drawn as the 5×8 missing-glyph outline, and everything after them on the line shifts: the missing glyph's advance (6) is not the real glyph's advance, and our layouts rely on exact advances and negative `space` advances. Menu backgrounds disappear completely; only a row of outlines shows to the left of the window. It stays broken until the renderer is rebuilt (pack reload or restart). **Expected** As in vanilla 26.3, every glyph keeps rendering for the whole session. **Steps to reproduce** 1. Join play.foxygame.net and accept the server resource pack. 2. Open the tab list, then the profile, cases and server selector menus from the hotbar items, and play for a minute so that health and food change. 3. The menu backgrounds, the HUD and the sidebar break as described (screenshots attached). **Cause** - A bitmap provider whose sheet is not in the `minecraft` namespace is not put in the HUD atlas: each glyph is copied on first use into the reserved run-time region. https://github.com/horizon-rust/horizon/blob/c51dcda0118881824ddf9be4e8caaa4a8541aee7/crates/horizon-client-render/src/font.rs#L272 - That region is only `GLYPH_ROWS = 512` rows, filled as shelves and never freed. https://github.com/horizon-rust/horizon/blob/c51dcda0118881824ddf9be4e8caaa4a8541aee7/crates/horizon-client-render/src/hud.rs#L89 - `Region::place` returns `None` when the region is full. https://github.com/horizon-rust/horizon/blob/c51dcda0118881824ddf9be4e8caaa4a8541aee7/crates/horizon-client-render/src/font.rs#L534-L563 - `glyph_of` then caches `self.missing` for that character, so it stays missing until `reset_cache()`, which only runs when the renderer is rebuilt or the font options change. https://github.com/horizon-rust/horizon/blob/c51dcda0118881824ddf9be4e8caaa4a8541aee7/crates/horizon-client-render/src/font.rs#L698-L711 - Our pack has 184,442 bitmap glyphs outside the atlas (about 453 million texels). Menu background glyphs are up to 256×252, so the region holds only about two shelves of them. **Suggested fix** 1. When `Region::place` fails, reset the region and every cached glyph that lives in it (what `reset_cache` does, with a new generation so cached layouts are redone), then retry once, instead of caching the missing glyph. 2. Make the region larger (for example 2048 rows or more), or give run-time glyphs their own texture or array texture that can grow, so the glyphs of one screen always fit. 3. Never cache the missing glyph for a character whose glyph exists but did not fit. Moving the pack's font sheets into `minecraft:font/` (so they go into the HUD atlas) does not work for us: they add up to about 900 MiB of RGBA and would overflow the 16384×16384 HUD atlas. <img width="1838" height="895" alt="Image" src="https://github.com/user-attachments/assets/8dadd775-5014-43c7-b652-17580717c100" /> <img width="1918" height="1035" alt="Image" src="https://github.com/user-attachments/assets/864d85ec-4a92-4c9e-96ba-a3f5c4048b93" /> <img width="1920" height="1037" alt="Image" src="https://github.com/user-attachments/assets/2271577e-919e-4c3b-a299-d8ab9997a0bb" /> <img width="744" height="568" alt="Image" src="https://github.com/user-attachments/assets/bc98cde5-2e97-4a00-83cf-7915a8822ff8" /> <img width="1422" height="341" alt="Image" src="https://github.com/user-attachments/assets/a9188f29-39d3-464e-ae93-b54727ada1a6" /> <img width="1538" height="898" alt="Image" src="https://github.com/user-attachments/assets/d9196bd9-8444-4d23-9096-a01511706b62" />
Author
Owner

@Joansitoh commented on GitHub (Nov 1, 2026):

🤖 Agent: /claim

Claimed by Joansitoh's AI agent (Claude Code, Sonnet 5.5), not by Joansitoh personally.

Cause: bitmap sheets outside the minecraft namespace are not placed in the HUD atlas; each glyph is copied on first use into a reserved region (GLYPH_ROWS = 512, hud.rs). Region::place (crates/horizon-client-render/src/font.rs) returns None when the region is full and rows are never freed; Font::glyph_of then does resolve(..).unwrap_or(self.missing) and caches missing permanently. reset_cache only runs on a renderer rebuild or a font-option change. Vanilla's FontSet/GlyphStitcher grows its textures, so it never runs out.

Plan: do not cache missing when the region was merely full; flag it and clear the glyph caches (same body as reset_cache, bumping the generation so layout caches keyed on Font::epoch() invalidate) at a frame boundary (a new Font::begin_frame()), because quads queued in the current frame still hold the old rects. Unit test with a tiny region and many sheet glyphs.

<!-- gh-comment-id:6555871085 --> @Joansitoh commented on GitHub (Nov 1, 2026): 🤖 Agent: /claim Claimed by Joansitoh's AI agent (Claude Code, Sonnet 5.5), not by Joansitoh personally. Cause: bitmap sheets outside the `minecraft` namespace are not placed in the HUD atlas; each glyph is copied on first use into a reserved region (`GLYPH_ROWS = 512`, `hud.rs`). `Region::place` (`crates/horizon-client-render/src/font.rs`) returns `None` when the region is full and rows are never freed; `Font::glyph_of` then does `resolve(..).unwrap_or(self.missing)` and caches `missing` permanently. `reset_cache` only runs on a renderer rebuild or a font-option change. Vanilla's `FontSet`/`GlyphStitcher` grows its textures, so it never runs out. Plan: do not cache `missing` when the region was merely full; flag it and clear the glyph caches (same body as `reset_cache`, bumping the generation so layout caches keyed on `Font::epoch()` invalidate) at a frame boundary (a new `Font::begin_frame()`), because quads queued in the current frame still hold the old rects. Unit test with a tiny region and many sheet glyphs.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#1785
No description provided.