Description
Reported by Reuben Thomas (JUCE) on Discord
In JUCE, we call OleInitialize (nullptr)
shortly after startup, and OleUninitialize()
on shutdown after closing all COM resources.
For WinRT, I know we're supposed to call winrt::init_apartment()
instead. I've read in a few places that it's actually fine (or even recommended) to skip calling winrt::uninit_apartment
, but that advice seems to focus on applications rather than plugins. Given that we may be loaded and unloaded multiple times over the lifetime of a process, I'd prefer to clean up properly each time.
With the context out of the way, I'm seeing a crash on shutdown inside the final call to OleUninitialize()
for JUCE apps that balance these COM setup/teardown calls. This happens after the message loop has exited and the message queue has been torn down. I'm omitting the stack trace for brevity, but it ends up crashing inside OleUninitialize
while trying to call the destructor of IMidiSessionTracker
, which seems to be owned by IMidiClientInitializer
.
In the debugger, it appears that immediately after calling CoCreateInstance
to make an IMidiClientInitializer
, the returned object has a refcount of 2. This is also true at the point where we call Shutdown
to close down our client instance. This means, even if we call release on our strong ref before reaching OleUninitialize
, something else keeps the object alive with its own strong ref. This seems a bit weird - I wouldn't expect another object to hold a strong ref to an object we created, especially after we've called Shutdown to let the service know that we're about to go away.
This seems like a lifetime bug to me. I wonder, can anyone else can confirm?
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
No status
Activity