ValveSoftware / halflife

Half-Life 1 engine based games
Other
3.71k stars 625 forks source link

GoldSrc RemoveFontResource() bug for custom fonts #967

Closed ghost closed 11 years ago

ghost commented 11 years ago

(This bug takes place on Windows only)

When custom font resources are listed in TrackerScheme.res/Scheme/CustomFontFiles section, GoldSrc engine calls AddFontResource() for every of them. So, it's logical that engine calls RemoveFontResource() for these fonts when shutting down. Unfortunately, there is a nasty RemoveFontResource() bug/feature: deleted font resources are staying visible for operating system until reboot, and are locked by OS - RemoveFontResource() does not unregister them completely.

The same RemoveFontResource() issue was discussed on Stack Overflow.

Isn't it better to call AddFontResourceEx() with FR_PRIVATE flag instead of AddFontResource()? This will fix OS font visibility issue, and also doesn't require to unregister fonts (the OS will do this itself, see MSDN; but if you want, RemoveFontResource() calls may be simply replaced by RemoveFontResourceEx() calls, see below). MSDN also says that custom fonts will take priority over system ones but I can't get this to work, system font is loaded anyway if it's name matches the custom font's name.

To summarize, the fastest way to fix this is to perform the following WinAPI calls replacement:

Old WinAPI call New WinAPI call
AddFontResource( lpszFileName ) AddFontResourceEx( lpszFileName , FR_PRIVATE, 0)
RemoveFontResource( lpszFileName ) RemoveFontResourceEx( lpszFileName , FR_PRIVATE, 0)

Please note that the second parameter in each pair of AddFontResourceEx() and RemoveFontResourceEx() must be the same.

ghost commented 11 years ago

@alfred-valve Thank you!