On Tue Nov 19 07:50:09 2024 +0000, Rémi Bernon wrote:
Giving it a quick look it seems like the game is doing the following:
- Creates a MF media session.
- Creates a MF media source,
- Creates a MF topology with the media source,
- IMFMediaSession_BeginGetEvent (then handles the produced events asynchronously)
- IMFMediaSession_ClearTopologies
- IMFMediaSession_SetTopology
- IMFMediaSession_Start
Then, when the user selects another character, it does: 8. IMFMediaSource_Shutdown 9. loops to 2. The IMFMediaSession_Start call queues an internal media session START command, that subscribes to media source events and then calls IMFMediaSource_Start. It then asynchronously waits until the corresponding MESourceStarted event is received before completing its START command with a corresponding media session event. The media session command queue uses its own list of commands and doesn't queue additional async calls while a media source command is pending. Now, the game IMFMediaSource_Shutdown call can sometimes be received after a IMFMediaSource_Start call has been made by the media session, but before the media source async command has been executed. When the command is executed, the media source has been shutdown already and it cannot queue any kind of event anymore for the media session to receive it. The media session is then stuck in its PENDING command state, and cannot process any other asynchronous commands. This looks to me like a media session bug, and it should instead be robust to this, especially as in this use case the ClearTopologies command should probably ignore any previous error or forever pending commands.
Thanks for the info. I made a test which shows that `MFUnlockWorkQueue()` does not purge pending items in Windows and instead they are processed. To fix this we need only pass FALSE to `CloseThreadpoolCleanupGroupMembers()`. On top of that, if we delay shutting down the event queue until the source is destroyed, and enqueue events with status MF_E_SHUTDOWN for commands handled after shutdown, it seems to fix the hang. I'll do some more testing. Since we can no longer rely on the event queue tracking shutdown status, we'll need this commit too.