Skip to content

Let go of a rich-text run's color once nothing draws with it - #344

Merged
LogicalError merged 1 commit into
mainfrom
tachyonui/run-color-slots
Nov 26, 2026
Merged

LogicalError merged 1 commit into
mainfrom
tachyonui/run-color-slots

Conversation

@LogicalError

Copy link
Copy Markdown
Owner

A rich-text run with its own color added a color style each time that color changed, and none was ever let go. The style table grew without limit under an animated run color. This is what's left of the growth #307 fixed for app colors.

What went wrong

  • ContentRun::color, ContentRun::background and a link's colors are drawn with color styles.
  • The text system registered them by value as it drew (RegisterColorStyle):
    • Equal colors shared a style.
    • A new color added one, and it stayed for good.
  • So 250 frames of a run whose color and background changed every frame added 504 styles.

The fix

  • A pool of run colors (SkribidiContext::RunColorStyle):
    • Each color gets a style of its own, made with CreateColorStyle and shared by the runs in that color.
    • A color nothing has drawn with for 16 frames is let go (DestroyColorStyle). The text system's sweep does it, every 8 frames.
    • The same 250 frames now add 47 styles, and the count stays there: freed slots are reused.
  • Cached scopes:
    • A cached scope doesn't draw its text again while its capture is shown, so drawing can't keep its colors.
    • The capture notes the run colors it used, next to its glyph atlas entries.
    • Each ReplayAtlasTouches keeps them.
    • If one went anyway, the replay returns false and the scope draws again. A slot reused for another color never shows in an old capture.
  • Theme reload: ClearAll frees every style. The pool sees the new StyleManager::Generation and forgets its slots.
  • Where it's used:
    • text drawing, for run colors, backgrounds and link underlines
    • the selectable rich-text editor, in place of RegisterColorStyle

Tests

  • New: ARunColorThatChangesEveryFrameDoesNotGrowTheStyles draws 250 frames of a changing run color and background. It failed before the fix.
  • New: ACachedScopeKeepsItsRunColorsUntilOneGoes:
    • 200 frames of replays keep a captured run color.
    • 200 frames without one let it go, and the replay returns false.
  • Changed: the run color tests used to compare a draw's style index with RegisterColorStyle(color)'s. A run color now has a style of its own, so they check that it shows the same color: the same VisualColorStyle, pointing at the same atlas texel.
  • Passing on Debug and Release:
    • gui_core_tests
    • gui_vulkan_tests, gui_d3d12_tests and gui_sdlgpu_tests
    • gui_gpu_tests on Vulkan, Direct3D 12 and SDL GPU

A run's own color (ContentRun::color or background, a link's) was
registered as a color style when the text was drawn, and never let go: a
run whose color changed every frame added a style a frame.

- The text system keeps a color style for each run color, shared by the
  runs in it, and lets go of one nothing has drawn with for 16 frames.
- A cached scope's capture notes the run colors it used; showing it again
  keeps them. One that went makes the scope draw again, so a reused slot
  never shows in an old capture.
- A theme reload, which clears every style, empties the pool.
@LogicalError
LogicalError merged commit 2ccb7fd into main Nov 26, 2026
9 checks passed
@LogicalError
LogicalError deleted the tachyonui/run-color-slots branch November 26, 2026 20:35
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

Successfully merging this pull request may close these issues.

1 participant