MuseScore icon indicating copy to clipboard operation
MuseScore copied to clipboard

[MU4 Issue] Crash when disconnecting headphones on Windows

Open krischan941 opened this issue 2 years ago • 23 comments

Describe the bug Musescore crashes when I disconnect my bluetooth In-Ear-Headphones by putting them back in the in-ears case. It crashes every time doing so.

Edit by @shoogle: it affects other kinds of headphones too, including USB and 3.5mm audio jack.

To Reproduce Steps to reproduce the behavior:

  1. Connect headphones to your PC via Bluetooth, USB, or 3.5mm audio jack
  2. start Musescore (and play back some content)
  3. pause playback
  4. disconnect headphones --> Crash

Expected behavior It doesn't crash and instead maps the output to the PC speakers as my other applications do.

Platform information

  • OS: Windows 11 on a Huawei Matebook 2020 AMD

Additional context I installed Musescore via Musehub today.

krischan941 avatar Dec 07 '22 22:12 krischan941

Musescore also won't load if my default audio device (laptop speakers) is selected, but it will if a Bluetooth audio device is selected.

tjfsteele avatar Dec 15 '22 16:12 tjfsteele

@Valdessir, were your wired earphones USB or standard 3.5mm audio jack?

shoogle avatar Dec 18 '22 13:12 shoogle

Ok thanks. It was mentioned in #15308 that it affects USB headphones too, so it appears that the crash occurs whenever the current audio device gets disconnected, regardless of connection type.

shoogle avatar Dec 18 '22 13:12 shoogle

It also prevents musescore from launching in some cases

On Sun, 18 Dec 2022, 13:53 Peter Jonas, @.***> wrote:

Ok thanks. It was mentioned in #15308 https://github.com/musescore/MuseScore/issues/15308 that it affects USB headphones too, so it appears that the crash occurs whenever the current audio device gets disconnected, regardless of connection type.

— Reply to this email directly, view it on GitHub https://github.com/musescore/MuseScore/issues/15029#issuecomment-1356803232, or unsubscribe https://github.com/notifications/unsubscribe-auth/AN3CV4ENF3XBYGGRRRGMWM3WN4JMPANCNFSM6AAAAAASXLVCBA . You are receiving this because you commented.Message ID: @.***>

tjfsteele avatar Dec 18 '22 14:12 tjfsteele

I have the same issue with Musescore 4 crashing on startup. I was able to get it to work by:

  1. Setting the audio to 16bit 44kHz
  2. Setting my Sound Blaster Z SE to Direct Mode. Normal mode will not work.

I think they may a bit of work to do with the audio engine. From what I can tell, it won't work set to 24bit 96 or 48k. Well at least on my system. (Core I9, 64GB RAM, Windows 11)

brondeau01 avatar Dec 19 '22 00:12 brondeau01

I use a pair of Logitech pro X wireless headphones (USB wireless dongle) and have had no issues. Even when swapping the output device to my speakers. However a friend of mine only has a pair of EPOS wired headphones (3.5mm) that plug into an EPOS external USB DAC as his audio out and he is unable to launch the program with them plugged in (it just instantly crashes)

He can launch the program without the headphones plugged in, but if he then plugs them back in again and then tries going to the IO settings to set the headphones as the audio out, the program crashes trying to render the IO pannel.

What's interesting is that the audio still works in the program as he was streaming it to me over discord and I could hear it but he couldn't.

MrSimmmons avatar Dec 19 '22 12:12 MrSimmmons

It crashed with my USB-C speaker, I wanted to show my piece to someone for feedback, so turned my speaker on, changed the audio device to it, played my piece, turned my speaker off, and then lost my piece!

itsmorethantech avatar Dec 20 '22 07:12 itsmorethantech

This happens whenever the audio engine is reset. When I open up Musecore 3 it will crash Musecore 4 after startup has finished loading.

Attackoh avatar Dec 20 '22 14:12 Attackoh

I'm seeing the same issue on an older computer on both with my default audio speakers and wired headphones.

OS: Windows 8.1 Audio: Realtek HD Audio

Changing the audio output source doesn't help.

deepankarc avatar Dec 30 '22 08:12 deepankarc

Can reproduce with 4.0 release. Will investigate with latest master and report back.

L0uisc avatar Dec 30 '22 17:12 L0uisc

I'm currently looking for a fix. Would be great if you could test this build: https://www.dropbox.com/s/086mhm28hlsv8dr/MuseScore-4.0.0.223640054-x86_64.zip?dl=0 and upload the logs from %localappdata%\MuseScore\MuseScore4Development\logs. Thanks in advance!

cbjeukendrup avatar Dec 30 '22 18:12 cbjeukendrup

@cbjeukendrup no crash, but playback is stuck even if I plug in the headphones again. Playback resumes once I go to Edit->Preferences->IO and change the Audio device to the "Realtek HD Audio 2nd output". Changing back to "System default" can output sound after that again.

L0uisc avatar Dec 30 '22 18:12 L0uisc

logs.zip

Here are the logs.

L0uisc avatar Dec 30 '22 18:12 L0uisc

I have a similar issue where whenever Musescore tries to use my SoundblasterX G6 as its audio source it crashes, whether that be on startup (as it selects it by default) or when I select it within the I/O settings (after launching musescore with the soundblaster unplugged to force it to select my monitor as the output audio device, then plugging it back in). The build @cbjeukendrup linked stops musescore from crashing, but playback sounds horrendous - it's tempo changes erratically and the sound is very "crunchy" (don't know how else to describe it) for both MS Basic and Muse Keys.

Here's a log file of me playing around in your build @cbjeukendrup if that helps.

cmoodie avatar Dec 31 '22 04:12 cmoodie

@cbjeukendrup I don't know exactly what you found in your investigation and how exactly MU4 handles audio output, but it seems like it doesn't listen to Windows event notifications for audio device changes. It just tries to find the "best" output device on boot, then keeps using it until someone changes it in Edit->Preferences->IO. If it is unplugged, Windows removes the audio device in the kernel, but MU4 still has a handle to it and tries to use it. This crashes (obviously) when the handle is stale.

MU4 should probably use the OS notifications to update its output device handles as appropriate. It should also be able to handle the condition of no valid output devices.

I can test the second case for you, as I'm on a Win10 desktop with my headphones as my only output device. If I unplug them, I don't have an audio output device at all.

L0uisc avatar Dec 31 '22 12:12 L0uisc

@L0uisc @cmoodie Thanks for testing! I have two new test versions, and it would be great if you could try if one of these resolves the problem (including the "crunchy" playback):

  • wasapi_autoconvert: https://www.dropbox.com/s/xqyh83m21l0cngg/MuseScore-wasapi_autoconvert-4.0.0.230022210-x86_64.zip?dl=0
  • wasapi_closest_convert_manually: https://www.dropbox.com/s/n9nxhs3g9laurci/MuseScore-wasapi_closest_convert_manually-4.0.0.230022210-x86_64.zip?dl=0

And if you could upload the log files once again, that would be great. Thanks in advance!


@L0uisc You're right that MuseScore currently doesn't switch correctly when the system audio device changes. I will fix that separately. Before I do that, it would be great if you could also try to launch these builds when no audio output devices are connected, so that I can see a log file corresponding to this situation.

cbjeukendrup avatar Jan 03 '23 00:01 cbjeukendrup

@cbjeukendrup The wasapi_closest_convert_manually version works flawlessly for me - playback sounds great through both my monitor and my SoundblasterX G6 and I am able to switch between the audio sources no problem.

The wasapi_autoconvert version doesn't crash, but the playback doesn't work at all for either of my audio devices. I also noticed that the "Buffer size" option in the Audio I/O options is blank, and would remain blank even if I tried to select any of the three options.

Here are the logs.zip

cmoodie avatar Jan 03 '23 02:01 cmoodie

MuseScore_230103_223155.log ^ wasapi_closest_convert_manually log with no audio device plugged in. Playback cursor is stuck, but no crash.

MuseScore_230103_223558.log ^ wasapi_autoconvert log with no audio device plugged in. Identical result to the other build: cursor is stuck, but no crash.

Identical results to @cmoodie with audio device plugged in: wasapi_autoconvert doesn't play back at all, even with audio device plugged in. wasapi_closest_convert_manually plays back audio if audio device is plugged in.

L0uisc avatar Jan 03 '23 20:01 L0uisc

Thanks for testing! I made wasapi_closest_convert_manually into a Pull Request, see https://github.com/musescore/MuseScore/pull/15698!

cbjeukendrup avatar Jan 03 '23 20:01 cbjeukendrup

@cbjeukendrup I saw it and I left a comment there.

L0uisc avatar Jan 03 '23 20:01 L0uisc

A bit late but here are my logs, maybe it's useful. I started Musescore with onboard soundcard, later connected my bluetooth in ears, later disconnected in-ears. Both wasapi_closest_convert_manually and wasapi_autoconvert it automatically automatically switched sound devices accordingly, so here both work good. MuseScore_autoconvert.log MuseScore_convert_manually.log

krischan941 avatar Jan 08 '23 14:01 krischan941

Could you please test this build? https://github.com/musescore/MuseScore/suites/11016103548/artifacts/559020946

Eism avatar Feb 17 '23 14:02 Eism

@Eism That build has identical results to the wasapi_autoconvert build:

The wasapi_autoconvert version doesn't crash, but the playback doesn't work at all for either of my audio devices. I also noticed that the "Buffer size" option in the Audio I/O options is blank, and would remain blank even if I tried to select any of the three options.

Here is the log

cmoodie avatar Feb 18 '23 07:02 cmoodie

Works good here. Created Session (standard Sound Output), insert some notes, playback (works) --> connect headphones (bluetooth), playback (works)--> disconnect headphones, playback (works) --> repeat a few times (works) MuseScore_230219_224933.log

krischan941 avatar Feb 19 '23 22:02 krischan941

@cmoodie Your issue is fixed in https://github.com/musescore/MuseScore/pull/15698. This PR fixes an issue with disconnecting/connecting a new device.

Eism avatar Feb 20 '23 06:02 Eism

Retested on Win10 (no crash when disconnecting headphones)

DmitryArefiev avatar Mar 03 '23 14:03 DmitryArefiev