You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a code to create the tray icon when the mainwindow is closing that works ok on both Windows and MacOS, but crashes on Linux like 90% of the time.
Now me dev enviroment is on Windows so it is hard for me to tell what exactly causes the crash, but from what i see its random as sometimes the icon is created, but will likely crash after opening the main window and closing it again.
This is what is sent to the console:
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at Tmds.DBus.SourceGenerator.ComCanonicalDbusmenu.EmitLayoutUpdated(UInt32 revision, Int32 parent)
at Avalonia.FreeDesktop.DBusMenuExporter.DBusMenuExporterImpl.DoLayoutReset()
at Avalonia.Threading.DispatcherOperation.InvokeCore()
at Avalonia.Threading.DispatcherOperation.Execute()
at Avalonia.Threading.Dispatcher.ExecuteJob(DispatcherOperation job)
at Avalonia.Threading.Dispatcher.ExecuteJobsCore(Boolean fromExplicitBackgroundProcessingCallback)
at Avalonia.Threading.Dispatcher.Signaled()
at Avalonia.X11.X11PlatformThreading.CheckSignaled()
at Avalonia.X11.X11PlatformThreading.RunLoop(CancellationToken cancellationToken)
at Avalonia.Threading.DispatcherFrame.Run(IControlledDispatcherImpl impl)
at Avalonia.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken)
at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.StartCore(String[] args)
at Knossos.NET.Program.Main(String[] args)
Abortado (`core' generado)
in other pc, this is when i tried switching the visibility from true to false and to true again
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at Tmds.DBus.SourceGenerator.OrgKdeStatusNotifierItem.EmitNewTitle()
at Avalonia.FreeDesktop.StatusNotifierItemDbusObj.InvalidateAll()
at Avalonia.FreeDesktop.StatusNotifierItemDbusObj.SetTitleAndTooltip(String text)
at Avalonia.FreeDesktop.DBusTrayIconImpl.CreateTrayIcon()
at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
at Avalonia.Threading.SendOrPostCallbackDispatcherOperation.InvokeCore()
at Avalonia.Threading.DispatcherOperation.Execute()
at Avalonia.Threading.Dispatcher.ExecuteJob(DispatcherOperation job)
at Avalonia.Threading.Dispatcher.ExecuteJobsCore(Boolean fromExplicitBackgroundProcessingCallback)
at Avalonia.Threading.Dispatcher.Signaled()
at Avalonia.X11.X11PlatformThreading.CheckSignaled()
at Avalonia.X11.X11PlatformThreading.RunLoop(CancellationToken cancellationToken)
at Avalonia.Threading.DispatcherFrame.Run(IControlledDispatcherImpl impl)
at Avalonia.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken)
at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.StartCore(String[] args)
at Knossos.NET.Program.Main(String[] args)
Im disposing the tray icon when the main window is show and re-creating it when it is closed (because menu items needs updating), i also tried not to dispose it, create it once and just clear the items and toggle its visibility. But that also causes it to crash.
To Reproduce
On app.axaml.cs
TrayIcon? trayIcon = null;
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel()
};
desktop.MainWindow.Closing += (_, __) =>
{
desktop.ShutdownMode = ShutdownMode.OnExplicitShutdown;
StartTrayIcon();
};
}
base.OnFrameworkInitializationCompleted();
}
private async void StartTrayIcon()
{
trayIcon?.Dispose();
trayIcon = new TrayIcon
{
IsVisible = true,
ToolTipText = "test",
Icon = new WindowIcon(new Bitmap(AssetLoader.Open(new Uri("avares://{app}/Assets/avalonia-icon.ico")))),
Menu = new NativeMenu() { new NativeMenuItem("Loading...") }
};
while (!initIsComplete) { await Task.Delay(10); }
trayIcon.Menu?.Items.Clear();
var open = new NativeMenuItem("Open");
open.Click += (s, _) => {
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel()
};
desktop.MainWindow.Closing += (_, __) =>
{
desktop.ShutdownMode = ShutdownMode.OnExplicitShutdown;
StartTrayIcon();
};
desktop.MainWindow.Show();
desktop.ShutdownMode = ShutdownMode.OnLastWindowClose;
trayIcon?.Dispose();
GC.Collect();
}
};
trayIcon.Menu?.Add(open);
trayIcon.Menu?.Add(new NativeMenuItemSeparator());
// Menu and submenus here
trayIcon.Menu?.Add(new NativeMenuItemSeparator());
var close = new NativeMenuItem("Exit");
close.Click += (s, e) => {
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
trayIcon?.Dispose();
desktop.Shutdown();
}
};
trayIcon.Menu?.Add(close);
GC.Collect();
}
Describe the bug
I have a code to create the tray icon when the mainwindow is closing that works ok on both Windows and MacOS, but crashes on Linux like 90% of the time.
Now me dev enviroment is on Windows so it is hard for me to tell what exactly causes the crash, but from what i see its random as sometimes the icon is created, but will likely crash after opening the main window and closing it again.
This is what is sent to the console:
in other pc, this is when i tried switching the visibility from true to false and to true again
Im disposing the tray icon when the main window is show and re-creating it when it is closed (because menu items needs updating), i also tried not to dispose it, create it once and just clear the items and toggle its visibility. But that also causes it to crash.
To Reproduce
On app.axaml.cs
Expected behavior
No response
Avalonia version
11.2.3
OS
Linux
Additional context
Making a close to try function
The full code in question is here:
https://github.com/KnossosNET/Knossos.NET/blob/main/Knossos.NET/App.axaml.cs
The text was updated successfully, but these errors were encountered: