Skip to content

[BUG] Crash on shutdown while calling OleUniitialize #557

Open
@Psychlist1972

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug 🐞Something isn't workingfixed-awaiting-public-release 🕙Fixed in our internal builds. Waiting to make its way to a public release.

Type

Projects

  • Status

    No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions