Clear wxFontEnumerator face names cache on library shutdown
Don't rely on it being done during statics cleanup as this doesn't work if the library is shutdown and re-initialized. Use a module to do the cleanup, just as it's already done for a lot of other global data in wx.
This commit is contained in:
parent
5c17c4b745
commit
5a13e4eda2
@ -26,6 +26,31 @@
|
||||
#if wxUSE_FONTENUM
|
||||
|
||||
#include "wx/fontenum.h"
|
||||
#include "wx/module.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
// Cached result of GetFacenames().
|
||||
wxArrayString gs_allFacenames;
|
||||
|
||||
// Module used to ensure the cache is cleared on library shutdown and so is not
|
||||
// reused if it re-initialized again later.
|
||||
class wxFontEnumCacheCleanupModule : public wxModule
|
||||
{
|
||||
public:
|
||||
wxFontEnumCacheCleanupModule() { }
|
||||
|
||||
bool OnInit() wxOVERRIDE { return true; }
|
||||
void OnExit() wxOVERRIDE { gs_allFacenames.clear(); }
|
||||
|
||||
private:
|
||||
wxDECLARE_DYNAMIC_CLASS(wxFontEnumCacheCleanupModule);
|
||||
};
|
||||
|
||||
wxIMPLEMENT_DYNAMIC_CLASS(wxFontEnumCacheCleanupModule, wxModule);
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
@ -79,7 +104,8 @@ bool wxFontEnumerator::IsValidFacename(const wxString &facename)
|
||||
{
|
||||
// we cache the result of wxFontEnumerator::GetFacenames supposing that
|
||||
// the array of face names won't change in the session of this program
|
||||
static wxArrayString s_arr = wxFontEnumerator::GetFacenames();
|
||||
if ( gs_allFacenames.empty() )
|
||||
gs_allFacenames = wxFontEnumerator::GetFacenames();
|
||||
|
||||
#ifdef __WXMSW__
|
||||
// Quoting the MSDN:
|
||||
@ -95,7 +121,7 @@ bool wxFontEnumerator::IsValidFacename(const wxString &facename)
|
||||
#endif
|
||||
|
||||
// is given font face name a valid one ?
|
||||
if (s_arr.Index(facename, false) == wxNOT_FOUND)
|
||||
if (gs_allFacenames.Index(facename, false) == wxNOT_FOUND)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user