Skip to content

Fix TextEdit font cache invalidation when font resources change - #125717

Open
huanxiangxingyun wants to merge 5 commits into
godotengine:masterfrom
huanxiangxingyun:fix/125687-issue-fix
Open

huanxiangxingyun wants to merge 5 commits into
godotengine:masterfrom
huanxiangxingyun:fix/125687-issue-fix

Conversation

@huanxiangxingyun

Copy link
Copy Markdown
Contributor

What problem(s) does this PR solve?

Additional information

This issue falls into the same category of font cache invalidation problems as the one I previously addressed. While the root causes differ, in this specific case, TextEdit determines whether to update its cache by checking if the font resource objects are identical; however, when FontVariation.base_font changes, the external object itself remains the same. Consequently, the stale glyph cache continues to reference font resource IDs (RIDs) that have already been released.
The solution in this PR involves listening for the "changed" signal emitted by the font resource, ensuring that the text cache is explicitly invalidated whenever the internal content of the font changes.

@huanxiangxingyun
huanxiangxingyun requested a review from a team as a code owner November 22, 2026 14:16
@YeldhamDev YeldhamDev added this to the 4.x milestone Nov 22, 2026
@bruvzg
bruvzg self-requested a review November 22, 2026 14:34
Comment thread scene/gui/text_edit.cpp Resolved
Comment thread scene/gui/text_edit.cpp Resolved
Comment thread scene/gui/text_edit.cpp Outdated
Comment on lines +10230 to +10231
observed_font->disconnect_changed(
callable_mp(this, &TextEdit::_font_changed));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary, signals are disconnected on deletion

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the redundant disconnection in the destructor. Thanks!

huanxiangxingyun and others added 3 commits November 23, 2026 19:52
Line break optimization

Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
Line break optimization

Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
Comment thread scene/gui/text_edit.h Outdated
Array st_args;

void _clear();
Ref<Font> observed_font;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding this, could we add a getter for the font that is in text and use that instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your review comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parameter "fd" is null errors when setting a FontVariation variable's base_font used as a font theme override of CodeEdit to FontVariation.new()

4 participants