Skip to content
This repository was archived by the owner on Mar 30, 2019. It is now read-only.
This repository was archived by the owner on Mar 30, 2019. It is now read-only.

MediaSessionCallback Access Violation #838

Open
@Wufflez

Description

@Wufflez

I'm having a problem with the media session callback object used for asynchronously receiving media session events.

My problem is when shutting down the media session, in a similar manner as to seen here, I cannot safely dispose of the MediaSessionCallback object without having a small chance of causing a fatal AccessViolation.

My code for shutting down works like follows:

  1. MediaSession.Close() is called
  2. My thread then waits on 'close' event; similar to the MSDN example
  3. The MediaSessionCallback OnEvent delegate receives the MESessionClosed event and sets the 'close' event my thread is waiting on.
  4. MediaSession.Shutdown() is called to make sure it releases any resources.
  5. MediaSession.Dispose() is called to release the media session itself.
  6. MediaSessionCallback.Dispose() is called to release the callback object.

The problem seems to be that if my thread gets to steps 5 and 6 too quickly, media foundation crashes with an access violation on the standard async callback work queue thread.

For testing purposes, the problem can be reproduced 100% of the time by cheating and bias the race condition by adding a 1ms delay to the MediaSessionCallback function after setting the event, to make sure the thread lingers in the callback object a bit longer. Of course, doing the opposite, and putting a magic sleep before calling dispose on the media session & callback object, the probability of the crash can be reduced greatly. This is, however, a bit of a silly solution that would still give me no strong guarantees.

Am I doing something wrong with the MediaSessionCallback object? I cannot see an obvious way to correctly detect when the callback thread has safely exited the callback object. This is causing me a bit of a headache because the software I'm writing has to create & destroy media sessions frequently, and also be running for long periods of time without crashing. If my explanation is not sufficient, please let me know. I could probably even write a small console application or something that demonstrates the problems I'm having in code.

Any ideas? Suggestions?

Thanks in advance,

Adam

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions