disable clearing event tables by default, only do it if wxUSE_MEMORY_TRACING is used: this fixes the problems with events not being dispatched correctly when the library is reinitialized

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46201 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-05-24 23:53:05 +00:00
parent 2afb9e1690
commit a0826b119e
2 changed files with 25 additions and 22 deletions

View File

@@ -2285,8 +2285,10 @@ public:
// Clear table // Clear table
void Clear(); void Clear();
#if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
// Clear all tables // Clear all tables
static void ClearAll(); static void ClearAll();
#endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING
protected: protected:
// Init the hash table with the entries of the static event table. // Init the hash table with the entries of the static event table.

View File

@@ -107,22 +107,26 @@ const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] =
{ DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL, 0, 0, (wxObjectEventFunction)NULL, NULL) }; { DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL, 0, 0, (wxObjectEventFunction)NULL, NULL) };
#ifdef __WXDEBUG__ // wxUSE_MEMORY_TRACING considers memory freed from the static objects dtors
// Clear up event hash table contents or we can get problems // leaked, so we need to manually clean up all event tables before checking for
// when C++ is cleaning up the static object // the memory leaks when using it, however this breaks re-initializing the
// library (i.e. repeated calls to wxInitialize/wxUninitialize) because the
// event tables won't be rebuilt the next time, so disable this by default
#if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
class wxEventTableEntryModule: public wxModule class wxEventTableEntryModule: public wxModule
{ {
DECLARE_DYNAMIC_CLASS(wxEventTableEntryModule)
public: public:
wxEventTableEntryModule() { } wxEventTableEntryModule() { }
bool OnInit() { return true; } virtual bool OnInit() { return true; }
void OnExit() virtual void OnExit() { wxEventHashTable::ClearAll(); }
{
wxEventHashTable::ClearAll(); DECLARE_DYNAMIC_CLASS(wxEventTableEntryModule)
}
}; };
IMPLEMENT_DYNAMIC_CLASS(wxEventTableEntryModule, wxModule) IMPLEMENT_DYNAMIC_CLASS(wxEventTableEntryModule, wxModule)
#endif
#endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// global variables // global variables
@@ -801,25 +805,20 @@ wxEventHashTable::~wxEventHashTable()
void wxEventHashTable::Clear() void wxEventHashTable::Clear()
{ {
size_t i; for ( size_t i = 0; i < m_size; i++ )
for(i = 0; i < m_size; i++)
{ {
EventTypeTablePointer eTTnode = m_eventTypeTable[i]; EventTypeTablePointer eTTnode = m_eventTypeTable[i];
if (eTTnode)
{
delete eTTnode; delete eTTnode;
} }
}
// Necessary in order to not invoke the
// overloaded delete operator when statics are cleaned up
if (m_eventTypeTable)
delete[] m_eventTypeTable; delete[] m_eventTypeTable;
m_eventTypeTable = NULL; m_eventTypeTable = NULL;
m_size = 0; m_size = 0;
} }
#if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
// Clear all tables // Clear all tables
void wxEventHashTable::ClearAll() void wxEventHashTable::ClearAll()
{ {
@@ -831,6 +830,8 @@ void wxEventHashTable::ClearAll()
} }
} }
#endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING
bool wxEventHashTable::HandleEvent(wxEvent &event, wxEvtHandler *self) bool wxEventHashTable::HandleEvent(wxEvent &event, wxEvtHandler *self)
{ {
if (m_rebuildHash) if (m_rebuildHash)