fix: graphics wrappers beside the starter no longer reach its window

ReShade installed for Direct3D as dxgi.dll in the simulator's folder was
loaded into the starter as well, and its window came up empty. The system
dxgi, d3d11, d3d9 and opengl32 are loaded first, and the window code's own
imports are handed those. The simulator still finds its wrappers.

--software-render draws the window on the processor, on Windows and X11,
for a machine on which it still comes up empty.
This commit is contained in:
maj00r
2026-11-15 14:41:48 +01:00
parent 744720d922
commit 91c496ab48
2 changed files with 105 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
using Avalonia;
using Avalonia.Threading;
using System;
using System.Linq;
using System.Threading.Tasks;
using StarterNG.Application;
using StarterNG.Infrastructure;
@@ -10,12 +11,24 @@ namespace StarterNG;
static class Program
{
/// <summary>
/// Drawn by the processor instead of the graphics card, for a machine on which the
/// window comes up empty. Started with <c>--software-render</c>.
/// </summary>
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.
SystemGraphicsLibraries.LoadFirst(typeof(Win32PlatformOptions).Assembly);
_softwareRender = args.Any(a => string.Equals(a, "--software-render", StringComparison.OrdinalIgnoreCase));
// Composition root first: everything below, including the crash handlers,
// resolves its collaborators from this graph.
AppServices.Initialize();
SystemGraphicsLibraries.LogShadowed();
AppDomain.CurrentDomain.UnhandledException += (_, e) =>
{
@@ -63,9 +76,25 @@ static class Program
};
}
// Each platform reads only its own options, so both can be given everywhere.
private static AppBuilder WithSoftwareRenderIfAsked(this AppBuilder builder) =>
_softwareRender
? builder
.With(new Win32PlatformOptions
{
RenderingMode = new[] { Win32RenderingMode.Software },
CompositionMode = new[] { Win32CompositionMode.RedirectionSurface }
})
.With(new X11PlatformOptions
{
RenderingMode = new[] { X11RenderingMode.Software }
})
: builder;
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithSoftwareRenderIfAsked()
.WithInterFont()
.WithDiagnosticsLogging()
.AfterSetup(_ => LogUiExceptions());