macOS tray icon crashes app on startup randomly
Describe the bug
I start my reproducer and randomly (60% chance or something) experience the same problem as #13055 however I verified I don't have any DYLD_ variable set.
It doesn't seem to occur with TrayIcon.Icons commented out in App.axaml.
To Reproduce
Steps to reproduce the behavior:
- Start app
- If it did not crash, stop app and go to 1
- See error
Expected behavior
No crash
Screenshots
--
Environment
- OS: macOS 14.3.1
- Avalonia-Version: 11.0.6 (default from template) and 11.0.8 both repro the issue, attached report for both
Additional context
macOS Problem Reporter logs: https://gist.github.com/nift4/e46eb7a14961e00cf99bd8a54126c152 Reproducer: Archiv.zip
From the log you posted the error occurs in the resize/restore of the window.
This should be the affected code. Try doing some debugging.
https://github.com/AvaloniaUI/Avalonia/blob/76caeedfd2baf1911f889011189d1c21657d2987/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm#L286-L343
It appears to be a Objective-C zombie string orginating from -[NSProcessInfo processName], which is deallocated by -[NSProcessInfo setProcessName]:
called by MacOptions::SetApplicationTitle
while Apple code is still using the old string to send CoreAnalytics event which was captured here:
while measuring the NSStatusItem added earlier (this is a hypothesis), because the window size is changed:
https://github.com/AvaloniaUI/Avalonia/blob/76caeedfd2baf1911f889011189d1c21657d2987/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm#L333C1-L333C50
I'm too unfamiliar with Avalonia code or macOS internals to investigate further or propose a fix.
.With(new MacOSPlatformOptions
{
DisableSetProcessName=true
})
works around the issue for now
@nift4 why do you open two similar issues? Can we close either one?
Different root causes
Let me explain a bit more
- This issue is: When opening app with tray icon enabled (not interacting with tray at all), it crashes
- The other one is: When clicking a menu entry in tray menu, it sometimes crashes the app Based on my investigation, these are unrelated bugs.