Belphemur / SoundSwitch

C# application to switch default playing device. Download: https://soundswitch.aaflalo.me/
https://soundswitch.aaflalo.me/
GNU General Public License v2.0
2.45k stars 175 forks source link

Crash after returning from sleep #1303

Open dalbitresb12 opened 11 months ago

dalbitresb12 commented 11 months ago

What happened?

I've been having this issue that appears randomly for a while where SoundSwitch would just stop working after turning my laptop back on after sleeping. After turning on, I would notice that the app had crashed. I don't know if it always happens after sleeping, but I definitely have had this happen a couple of times before.

Today I had a little time to try to find why SoundSwitch is crashing, and I found some interesting logs in Event Viewer. The SoundSwitch logs at %appdata%\SoundSwitch do not have anything related to this. The logs stop yesterday, which is when I put my laptop to sleep.

In case it is relevant, I have a Focusrite Scarlett 4i4 connected to my laptop and I don't usually disconnect it when I set my laptop to sleep.

I'm attaching a ZIP file with the Custom View filter I used to find the logs and the exported logs from my machine.

SoundSwitch Crash.zip

I'll also include the .NET Runtime crash here, but it is also visible from the exported logs in the ZIP file.

Error ``` Application: SoundSwitch.exe CoreCLR Version: 7.0.723.27404 .NET Version: 7.0.7 Description: The process was terminated due to an unhandled exception. Exception Info: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Stack: at SoundSwitch.Audio.Manager.Interop.Com.User.User32+NativeMethods.SendMessage(IntPtr, UInt32, IntPtr, System.Text.StringBuilder) at SoundSwitch.Audio.Manager.Interop.Com.User.User32+NativeMethods.SendMessage(IntPtr, UInt32, IntPtr, System.Text.StringBuilder) at SoundSwitch.Audio.Manager.Interop.Com.User.User32.GetWindowText(HWND) at SoundSwitch.Audio.Manager.WindowMonitor+<>c__DisplayClass6_0.b__0() at SoundSwitch.Audio.Manager.Interop.Com.Threading.ComThread+<>c__DisplayClass9_0`1[[System.ValueTuple`3[[System.UInt32, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].b__0() at System.Threading.Tasks.Task`1[[System.ValueTuple`3[[System.UInt32, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].InnerInvoke() at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef, System.Threading.Thread) at System.Threading.Tasks.Task.ExecuteEntry() at SoundSwitch.Audio.Manager.Interop.Com.Threading.ComTaskScheduler.<.ctor>b__2_0() at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) ```

Also, here's my config in case it is of any use.

SoundSwitchConfiguration.json ```json { "SelectedPlaybackDeviceListId": [], "SelectedRecordingDeviceListId": [], "SelectedDevices": [ { "Name": "Playback 1 + 2 (3- Focusrite USB Audio)", "Id": "{0.0.0.00000000}.{0a981ca5-326d-4673-9d4d-ccad0315ca44}", "Type": 0, "IsUsb": false, "DiscoveredAt": "2022-08-31T00:16:12.444377Z", "NameClean": "Playback 1 + 2 (Focusrite USB Audio)" }, { "Name": "Speakers / Headphones (Realtek Audio)", "Id": "{0.0.0.00000000}.{e9541d82-90f9-4ed0-900e-a8bdb61bca0c}", "Type": 0, "IsUsb": false, "DiscoveredAt": "2022-08-31T00:16:14.6269747Z", "NameClean": "Speakers / Headphones (Realtek Audio)" }, { "Name": "Analogue 1 + 2 (3- Focusrite USB Audio)", "Id": "{0.0.1.00000000}.{d7295b72-24ea-44d3-ad61-256939379432}", "Type": 1, "IsUsb": false, "DiscoveredAt": "2022-08-31T00:20:22.0304919Z", "NameClean": "Analogue 1 + 2 (Focusrite USB Audio)" }, { "Name": "Loopback L + R (3- Focusrite USB Audio)", "Id": "{0.0.1.00000000}.{48e674e3-499a-400f-bd8f-9e7d4e61f97f}", "Type": 1, "IsUsb": false, "DiscoveredAt": "2022-08-31T00:20:25.3695788Z", "NameClean": "Loopback L + R (Focusrite USB Audio)" }, { "Name": "Microphone (Realtek Audio)", "Id": "{0.0.1.00000000}.{99f878de-4035-4ad3-9f0a-93c22f8244c2}", "Type": 1, "IsUsb": false, "DiscoveredAt": "2022-08-31T00:20:25.910082Z", "NameClean": "Microphone (Realtek Audio)" }, { "Name": "Playback 3 + 4 (3- Focusrite USB Audio)", "Id": "{0.0.0.00000000}.{5367652d-d4c1-4d41-9a27-ded9e74278f3}", "Type": 0, "IsUsb": false, "DiscoveredAt": "2022-08-31T00:20:28.7011856Z", "NameClean": "Playback 3 + 4 (Focusrite USB Audio)" } ], "FirstRun": false, "PlaybackHotKey": { "Keys": 118, "Modifier": 3, "Enabled": true }, "RecordingHotKey": { "Keys": 117, "Modifier": 3, "Enabled": true }, "MuteRecordingHotKey": { "Keys": 77, "Modifier": 3, "Enabled": false }, "ChangeCommunications": true, "UpdateCheckInterval": 86400, "UpdateMode": 1, "TooltipInfo": 3, "CyclerType": 1, "NotificationSettings": 5, "Language": 0, "IncludeBetaVersions": false, "NotifyUsingPrimaryScreen": false, "AutoAddNewConnectedDevices": false, "LastDonationNagTime": "2023-04-09T23:30:50.2475826Z", "KeepSystrayIcon": false, "SwitchForegroundProgram": true, "SwitchIcon": 2, "ProfileSettings": [], "Profiles": [], "MigratedFields": [ "KeepSystrayIcon", "ProfileSettings_final", "LastDonationNagTime", "SwitchForegroundProgram_force_off", "CleanupSelectedDevices", "SwitchForegroundProgram_cleanup", "CleanupProfilesForeground", "SwitchForegroundProgram_fix" ], "UniqueInstallationId": "5b3c0236-e4e6-4de2-8547-59e9f6829385", "Telemetry": true, "QuickMenuEnabled": false } ```

Step to reproduce

I don't know exactly the steps, but I do know that this time it happened like this.

  1. Open SoundSwitch
  2. Put the laptop/PC to sleep (for almost 12 hours?)
  3. Turn it back on
  4. SoundSwitch should crash?

I know the steps probably won't reproduce the crash, so it might be something else or something specific to my machine.

Version

v6.7.2.0

What version of Windows are you seeing the problem on?

Windows 10

Relevant log output

No response

Belphemur commented 10 months ago

SoundSwitch monitor what is the current foreground application to see if a profile needs to be applied. I thought I had found a fix for this bug ... I'm not sure how I can correct it.

Basically, SoundSwitch couldn't get the new window name.

FreddieDev commented 10 months ago

I also have this but haven't been able to consistently reproduce it. It also occurs for me when waking the system from hibernation.