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:
@@ -26,6 +26,31 @@
|
|||||||
#if wxUSE_FONTENUM
|
#if wxUSE_FONTENUM
|
||||||
|
|
||||||
#include "wx/fontenum.h"
|
#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
|
// implementation
|
||||||
@@ -79,7 +104,8 @@ bool wxFontEnumerator::IsValidFacename(const wxString &facename)
|
|||||||
{
|
{
|
||||||
// we cache the result of wxFontEnumerator::GetFacenames supposing that
|
// we cache the result of wxFontEnumerator::GetFacenames supposing that
|
||||||
// the array of face names won't change in the session of this program
|
// 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__
|
#ifdef __WXMSW__
|
||||||
// Quoting the MSDN:
|
// Quoting the MSDN:
|
||||||
@@ -95,7 +121,7 @@ bool wxFontEnumerator::IsValidFacename(const wxString &facename)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// is given font face name a valid one ?
|
// 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 false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user