Skip to content

Fix font test segfault on SDL3 #3549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src_c/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,17 @@ font_dealloc(PyFontObject *self)
{
TTF_Font *font = PyFont_AsFont(self);
if (font && font_initialized) {
// In SDL3_ttf, it seems that closing a font after its library was
// destroyed segfaults. So only close if same generation.
// TODO SDL3:
// TTF docs say "A well-written program should call TTF_CloseFont()
// on any open fonts before calling this function!"
#if SDL_VERSION_ATLEAST(3, 0, 0)
if (self->ttf_init_generation == current_ttf_generation) {
TTF_CloseFont(font);
}
self->font = NULL;
#else
if (self->ttf_init_generation != current_ttf_generation) {
// Since TTF_Font is a private structure
// it's impossible to access face field in a common way.
Expand All @@ -1218,6 +1229,7 @@ font_dealloc(PyFontObject *self)
}
TTF_CloseFont(font);
self->font = NULL;
#endif
}

if (self->weakreflist) {
Expand Down
Loading