From f23a6887a812077b1e8e2d9ee68cfe1d5da5246c Mon Sep 17 00:00:00 2001 From: ddj4747 <139778357+ddj4747@users.noreply.github.com> Date: Sun, 19 Apr 2026 21:26:44 +0200 Subject: [PATCH] Patch std::map iterator assertion in hideToast --- src/wintoastlib.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/wintoastlib.cpp b/src/wintoastlib.cpp index 1bfb910..fac2d2c 100644 --- a/src/wintoastlib.cpp +++ b/src/wintoastlib.cpp @@ -927,15 +927,21 @@ bool WinToast::hideToast(_In_ INT64 id) { return false; } - auto& notifyData = iter->second; - auto result = notify->Hide(notifyData.notification()); + ComPtr notificationObj = iter->second.notification(); + + auto result = notify->Hide(notificationObj.Get()); if (FAILED(result)) { DEBUG_MSG("Error when hiding the toast. Error code: " << result); return false; } - notifyData.RemoveTokens(); - _buffer.erase(iter); + iter = _buffer.find(id); + if (iter != _buffer.end()) { + iter->second.markAsReadyForDeletion(); + iter->second.RemoveTokens(); + _buffer.erase(iter); + } + return SUCCEEDED(result); } @@ -948,9 +954,12 @@ void WinToast::clear() { auto safeCopy = _buffer; for (auto& data : safeCopy) { - auto& notifyData = data.second; - notify->Hide(notifyData.notification()); - notifyData.RemoveTokens(); + notify->Hide(data.second.notification()); + } + + for (auto& data : _buffer) { + data.second.markAsReadyForDeletion(); + data.second.RemoveTokens(); } _buffer.clear(); }