File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -1210,6 +1210,17 @@ font_dealloc(PyFontObject *self)
1210
1210
{
1211
1211
TTF_Font * font = PyFont_AsFont (self );
1212
1212
if (font && font_initialized ) {
1213
+ // In SDL3_ttf, it seems that closing a font after its library was
1214
+ // destroyed segfaults. So only close if same generation.
1215
+ // TODO SDL3:
1216
+ // TTF docs say "A well-written program should call TTF_CloseFont()
1217
+ // on any open fonts before calling this function!"
1218
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
1219
+ if (self -> ttf_init_generation == current_ttf_generation ) {
1220
+ TTF_CloseFont (font );
1221
+ }
1222
+ self -> font = NULL ;
1223
+ #else
1213
1224
if (self -> ttf_init_generation != current_ttf_generation ) {
1214
1225
// Since TTF_Font is a private structure
1215
1226
// it's impossible to access face field in a common way.
@@ -1218,6 +1229,7 @@ font_dealloc(PyFontObject *self)
1218
1229
}
1219
1230
TTF_CloseFont (font );
1220
1231
self -> font = NULL ;
1232
+ #endif
1221
1233
}
1222
1234
1223
1235
if (self -> weakreflist ) {
You can’t perform that action at this time.
0 commit comments