Fix backgroundog ACCESS_VIOLATION crash and Unicode file path URI handling
Two unrelated issues: (1) backgroundog.exe randomly crashes with 0xC0000005 ACCESS_VIOLATION errors during Windows message processing, (2) wallpaper selection crashes when file paths contain non-ASCII characters (e.g., Chinese: D:\壁纸\风景.jpg).
Changes
Exception Handling (backgroundog crash)
- Added
AppDomain.UnhandledExceptionandTaskScheduler.UnobservedTaskExceptionglobal handlers - Wrapped main processing loop with try-catch to isolate iteration failures
- Added
IntPtr.Zerovalidation before native API calls (GetForegroundWindow,GetWindowThreadProcessId) - Added PID validation after
GetWindowThreadProcessIdcalls
Files: App.cs, Windows.cs, Specification.cs
URI Creation (Unicode paths)
- Changed local file path URI creation to use
Path.GetFullPath()+UriKind.Absoluteinstead ofUriKind.RelativeOrAbsolute - Added detection for absolute file paths in
GetSource(string, string)overload to route through proper URI handling - Added fallback to preserve backward compatibility
File: Source.cs
// Before: fails with Chinese paths
return new Uri(Source, UriKind.RelativeOrAbsolute);
// After: normalizes and explicitly marks as absolute
string absolutePath = Path.GetFullPath(Source);
return new Uri(absolutePath, UriKind.Absolute);
All changes are defensive additions with no breaking changes to existing functionality.
Original prompt
This section details on the original issue you should resolve
<issue_title>Two Separate Issues - sucrose.backgroundog.exe Error Popup & Chinese Path Wallpaper Crash</issue_title> <issue_description>Issue 1: sucrose.backgroundog.exe Error Popup Description The process sucrose.backgroundog.exe randomly displays a popup error with the message: exception processing message 0xcc0000005 - unexpected parameters. Observed Behavior The error popup appears randomly during app usage No obvious functional crash of the entire app is caused, but the error interrupts usage. The error is directly associated with the sucrose.backgroundog.exe process. Issue 2: Wallpaper Customization Crash with Chinese Local Paths Description When using the app's custom wallpaper feature to select local images with Chinese characters in the file path (including Chinese folder names) or file names, the wallpaper function crashes immediately. Steps to Reproduce Open the app's wallpaper customization module and select the "Local Image" option. Browse and choose a local image where the file path or file name contains Chinese characters (e.g., D:\壁纸\风景图\山水.jpg or E:\个人图片\桌面背景.png). Click "Apply" – the wallpaper function crashes instantly, and the app automatically reverts to the default wallpaper. Expected Behavior The app should load and apply local wallpapers with Chinese paths/filenames normally without crashing. Actual Behavior The wallpaper function crashes immediately after selecting a local image with a Chinese path/filename, and the default wallpaper is applied automatically. Additional Notes The two issues are completely independent: the sucrose.backgroundog.exe error popup occurs randomly and is not triggered by the Chinese path wallpaper selection. Local images with English paths/filenames can be applied normally via the custom wallpaper feature. Online wallpapers and default wallpapers function without issues.</issue_description>
Comments on the Issue (you are @copilot in this section)
@Taiizor Which version of Sucrose are you using? Also, please follow the instructions below to send me the required file.Log File (Important) Share the diagnostic files by: Right click on the system tray icon -> Report Issue -> Create Log File or Open Sucrose settings (Gear icon) top-right -> System -> Log Files -> Create or Navigate to the Appdata folder
C:\Users\<UserName>\AppData\Roaming\Sucrose\Log</comment_new>
- Fixes Taiizor/Sucrose#155
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.