mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-27 17:09:37 +01:00
* fix: windows of the starter no longer come up black on Windows 11 25H2 Avalonia composes each window through a WinUI composition visual by default, and on 25H2 that visual was often left empty: the main window or a dialog opened later stayed black while the others drew. The starter has no see-through windows or backdrops, so every window now draws into its own redirection surface, still on the graphics card. --software-render comes after and keeps its own options. * test: the choice between window surfaces and the processor is covered The choice moves out of Program, which no test runs, into WindowSurfaces, where both branches are tested. Sonar's quality gate failed on the coverage of the new code. --------- Co-authored-by: maj00r <maj00r@host>
88 lines
2.6 KiB
C#
88 lines
2.6 KiB
C#
using Avalonia;
|
|
using Avalonia.Threading;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using StarterNG.Application;
|
|
using StarterNG.Infrastructure;
|
|
|
|
namespace StarterNG;
|
|
|
|
static class Program
|
|
{
|
|
|
|
private static bool _softwareRender;
|
|
|
|
[STAThread]
|
|
public static void Main(string[] args)
|
|
{
|
|
// Ahead of everything that could draw: what lies beside the starter is the simulator's.
|
|
var graphics = SystemGraphicsLibraries.TakeOnWindows();
|
|
graphics?.ServeTo(typeof(Win32PlatformOptions).Assembly);
|
|
|
|
_softwareRender = SoftwareRender.AskedIn(args);
|
|
|
|
// Composition root first: everything below, including the crash handlers,
|
|
// resolves its collaborators from this graph.
|
|
AppServices.Initialize();
|
|
if (graphics?.Note is { } note)
|
|
Diagnostics.Log(note);
|
|
|
|
AppDomain.CurrentDomain.UnhandledException += (_, e) =>
|
|
{
|
|
if (e.ExceptionObject is Exception ex)
|
|
Diagnostics.Log("Unhandled exception", ex);
|
|
Diagnostics.Flush();
|
|
};
|
|
|
|
TaskScheduler.UnobservedTaskException += (_, e) =>
|
|
{
|
|
Diagnostics.Log("Unobserved task exception", e.Exception);
|
|
e.SetObserved();
|
|
};
|
|
|
|
try
|
|
{
|
|
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Diagnostics.Log("Fatal", ex);
|
|
throw;
|
|
}
|
|
finally
|
|
{
|
|
Diagnostics.Flush();
|
|
}
|
|
}
|
|
|
|
private static AppBuilder WithDiagnosticsLogging(this AppBuilder builder)
|
|
{
|
|
DiagnosticsLogSink.Install();
|
|
return builder;
|
|
}
|
|
|
|
// After setup: the dispatcher takes its platform's implementation when first asked
|
|
// for. Not marked handled: a handler that failed half way leaves the state unknown,
|
|
// and the exception goes on to end the program as before, only no longer unexplained.
|
|
private static void LogUiExceptions()
|
|
{
|
|
Dispatcher.UIThread.UnhandledException += (_, e) =>
|
|
{
|
|
Diagnostics.Log("Unhandled UI exception", e.Exception);
|
|
Diagnostics.Flush();
|
|
};
|
|
}
|
|
|
|
// Without the switch the graphics card draws, into the window surfaces.
|
|
private static AppBuilder WithSoftwareRenderIfAsked(this AppBuilder builder) =>
|
|
WindowSurfaces.ApplyTo(builder, _softwareRender);
|
|
|
|
public static AppBuilder BuildAvaloniaApp()
|
|
=> AppBuilder.Configure<App>()
|
|
.UsePlatformDetect()
|
|
.WithSoftwareRenderIfAsked()
|
|
.WithInterFont()
|
|
.WithDiagnosticsLogging()
|
|
.AfterSetup(_ => LogUiExceptions());
|
|
}
|