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)
12101210{
12111211 TTF_Font * font = PyFont_AsFont (self );
12121212 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
12131224 if (self -> ttf_init_generation != current_ttf_generation ) {
12141225 // Since TTF_Font is a private structure
12151226 // it's impossible to access face field in a common way.
@@ -1218,6 +1229,7 @@ font_dealloc(PyFontObject *self)
12181229 }
12191230 TTF_CloseFont (font );
12201231 self -> font = NULL ;
1232+ #endif
12211233 }
12221234
12231235 if (self -> weakreflist ) {
You can’t perform that action at this time.
0 commit comments