AudioSwitcher icon indicating copy to clipboard operation
AudioSwitcher copied to clipboard

Strange exception: msvcrt.dll

Open osbeorn opened this issue 8 years ago • 8 comments

Hello,

I randomly encounter the following error in my program when using this library:

Exception thrown at 0x00007FF81DD03F80 (msvcrt.dll) in FireDeptStopwatch.exe: 0xC0000005: Access violation reading location 0x0000000014585ED8.

The following line of code is enough to trigger the exception: var sessions = audioController.DefaultPlaybackDevice.GetCapability<IAudioSessionController>();

Any clue what might be wrong?

osbeorn avatar Mar 07 '17 21:03 osbeorn

What operating system are you running on?

Does it happen immediately, or after the application has been running for some time?

xenolightning avatar Mar 07 '17 21:03 xenolightning

Win10 x64. It happens after sometime. And it seems quite random.

osbeorn avatar Mar 07 '17 22:03 osbeorn

The underlying COM object may get destroyed.

Taking a quick look at the session code, there may be some enhancements in that space regarding object lifecycle.

xenolightning avatar Mar 08 '17 19:03 xenolightning

One more thing ... My application is basically a stopwatch, which plays a command on start and plays another random audio track on end. It seems that just one specific audio track triggers this error.

The audio track is a 10s long .wav file of some song. The code used to play the track: using (var player = new SoundPlayer((UnmanagedMemoryStream) sound)) { player.Play(); }

osbeorn avatar Mar 09 '17 21:03 osbeorn

Are you able to create a gist or attach a piece of self contained code that can be used to reproduce it? If you can, it should be fairly easy to track down and fix.

xenolightning avatar Mar 09 '17 21:03 xenolightning

Here you go: fireDeptStopwatchGist.zip

Run the project, press Start, wait for the counter to start counting and then press Stop. You should get the mentioned exception.

osbeorn avatar Mar 10 '17 09:03 osbeorn

It seems that the main problem is this block of code: using (var player = new SoundPlayer((UnmanagedMemoryStream) sound)) { player.Play(); }

If I remove the using block and normally create a new SoundPlayer instance, the application stops crashing. It seems the SoundPlayer instance created inside the using block is getting disposed before it finishes playing the sound.

But if I remove your library, the SoundPlayer works fine even when using it with the using block.

osbeorn avatar Mar 10 '17 09:03 osbeorn

I had a look at this in the weekend, and it's definitely in the Session Initialization code.

I should be able to track it down, and make a fix for it. I'll tag the commit in here, once it's done.

Cheers.

xenolightning avatar Mar 12 '17 19:03 xenolightning