From: lx-s Date: Wed, 8 Jul 2026 12:44:16 +0000 (+0200) Subject: Use correct ccomptr for vistaaudio X-Git-Tag: 2.6.0.0~77 X-Git-Url: https://repos.lx-s.de/gitweb/?a=commitdiff_plain;h=f001551bc20a1d4bea4b4bec3ce4fa530c7eb783;p=winmute.git Use correct ccomptr for vistaaudio --- diff --git a/WinMute/VistaAudio.cpp b/WinMute/VistaAudio.cpp index c6e928f..7cef244 100644 --- a/WinMute/VistaAudio.cpp +++ b/WinMute/VistaAudio.cpp @@ -40,7 +40,7 @@ POSSIBILITY OF SUCH DAMAGE. Endpoint::~Endpoint() { if (sessionCtrl && wasapiAudioEvents != nullptr) { - sessionCtrl->UnregisterAudioSessionNotification(wasapiAudioEvents.get()); + sessionCtrl->UnregisterAudioSessionNotification(wasapiAudioEvents); } } @@ -115,11 +115,10 @@ bool VistaAudio::LoadAllEndpoints() continue; } - ep->wasapiAudioEvents = std::make_unique(this); - if (ep->wasapiAudioEvents) { - ep->sessionCtrl->RegisterAudioSessionNotification( - ep->wasapiAudioEvents.get()); - } + // Attach: the CComPtr takes over the initial reference from new, + // so the refcount stays balanced. + ep->wasapiAudioEvents.Attach(new VistaAudioSessionEvents(this)); + ep->sessionCtrl->RegisterAudioSessionNotification(ep->wasapiAudioEvents); hr = device->Activate( __uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER, diff --git a/WinMute/WinAudio.h b/WinMute/WinAudio.h index a16c871..e1efe4d 100644 --- a/WinMute/WinAudio.h +++ b/WinMute/WinAudio.h @@ -58,7 +58,10 @@ struct Endpoint { std::wstring deviceName; CComPtr endpointVolume; CComPtr sessionCtrl; - std::unique_ptr wasapiAudioEvents; + // VistaAudioSessionEvents is a ref-counted COM object; holding it in a + // CComPtr keeps its lifetime tied to the COM refcount instead of fighting + // it with a second owner. + CComPtr wasapiAudioEvents; bool wasMuted = false;