musescore / MuseScore

MuseScore is an open source and free music notation software. For support, contribution, bug reports, visit MuseScore.org. Fork and make pull requests!
https://musescore.org
Other
12.1k stars 2.62k forks source link

[MU4 Issue] Crash when disconnecting headphones on Windows #15029

Closed krischan941 closed 1 year ago

krischan941 commented 1 year ago

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

Additional context I installed Musescore via Musehub today.

tjfsteele commented 1 year ago

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

Valdessir commented 1 year ago

I experienced a crash as well in the release version with wired earphones. I didn't experience a crash in the beta, nightlies, nor the RC, but an automatic mapping to speakers.

(OS: Windows 11)

shoogle commented 1 year ago

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

Valdessir commented 1 year ago

@shoogle

Audio jack.

shoogle commented 1 year ago

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.

tjfsteele commented 1 year ago

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: @.***>

brondeau01 commented 1 year ago

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)

MrSimmmons commented 1 year ago

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.

itsmorethantech commented 1 year ago

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!

Attackoh commented 1 year ago

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

deepankarc commented 1 year ago

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.

L0uisc commented 1 year ago

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

cbjeukendrup commented 1 year ago

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!

L0uisc commented 1 year ago

@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 commented 1 year ago

logs.zip

Here are the logs.

cmoodie commented 1 year ago

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.

L0uisc commented 1 year ago

@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.

cbjeukendrup commented 1 year ago

@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):

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.

cmoodie commented 1 year ago

@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

L0uisc commented 1 year ago

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.

cbjeukendrup commented 1 year ago

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

L0uisc commented 1 year ago

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

krischan941 commented 1 year ago

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

Eism commented 1 year ago

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

cmoodie commented 1 year ago

@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

krischan941 commented 1 year ago

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

Eism commented 1 year ago

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

DmitryArefiev commented 1 year ago

Retested on Win10 (no crash when disconnecting headphones)