Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

macOS tray icon crashes app on startup randomly

Open nift4 opened this issue 1 year ago • 6 comments

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:

  1. Start app
  2. If it did not crash, stop app and go to 1
  3. 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

nift4 avatar Feb 10 '24 11:02 nift4

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

workgroupengineering avatar Feb 10 '24 11:02 workgroupengineering

It appears to be a Objective-C zombie string orginating from -[NSProcessInfo processName], which is deallocated by -[NSProcessInfo setProcessName]: grafik called by MacOptions::SetApplicationTitle grafik while Apple code is still using the old string to send CoreAnalytics event which was captured here: grafik 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.

nift4 avatar Feb 10 '24 12:02 nift4

            .With(new MacOSPlatformOptions
            {
                DisableSetProcessName=true
            })

works around the issue for now

nift4 avatar Feb 10 '24 12:02 nift4

@nift4 why do you open two similar issues? Can we close either one?

timunie avatar Feb 12 '24 06:02 timunie

Different root causes

nift4 avatar Feb 12 '24 08:02 nift4

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.

nift4 avatar Feb 12 '24 08:02 nift4