diff --git a/docs/changes.txt b/docs/changes.txt index 5c10df8f30..a97a63b588 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -629,6 +629,7 @@ wxMSW: - Fix bug with multiple default buttons in a dialog (Artur Wieczorek). - Improve tooltips wrapping after updating their text (Artur Wieczorek). - Fix checking menu items before appending them to the menu. +- Fix crash when adding/removing the same path to/from wxFileSystemWatcher. wxOSX: diff --git a/include/wx/msw/private/fswatcher.h b/include/wx/msw/private/fswatcher.h index 86f91dc3d0..fdbeef68a3 100644 --- a/include/wx/msw/private/fswatcher.h +++ b/include/wx/msw/private/fswatcher.h @@ -173,7 +173,7 @@ public: // worse, reused to point to another object) pointer in ReadEvents() so // just remember that this one should be removed when CompleteRemoval() // is called later. - m_removedWatches.insert(wxFSWatchEntries::value_type(path, watch)); + m_removedWatches.push_back(watch); m_watches.erase(it); return true; @@ -185,15 +185,20 @@ public: // this case we'll just return false and do nothing. bool CompleteRemoval(wxFSWatchEntryMSW* watch) { - wxFSWatchEntries::iterator it = m_removedWatches.find(watch->GetPath()); - if ( it == m_removedWatches.end() ) - return false; + for ( Watches::iterator it = m_removedWatches.begin(); + it != m_removedWatches.end(); + ++it ) + { + if ( (*it).get() == watch ) + { + // Removing the object from here will result in deleting the + // watch itself as it's not referenced from anywhere else now. + m_removedWatches.erase(it); + return true; + } + } - // Removing the object from the map will result in deleting the watch - // itself as it's not referenced from anywhere else now. - m_removedWatches.erase(it); - - return true; + return false; } // post completion packet @@ -249,7 +254,8 @@ protected: wxFSWatchEntries m_watches; // Contains the watches which had been removed but are still pending. - wxFSWatchEntries m_removedWatches; + typedef wxVector< wxSharedPtr > Watches; + Watches m_removedWatches; };