Compare commits

..

1 Commits

Author SHA1 Message Date
maj00r dc1f43d385 fix: on Windows the processor draws the starter's windows
Every way of the graphics card's failed on some machine. Avalonia's WinUI
composition visual left windows black on Windows 11 25H2, the Steam
overlay drew its frame counter over the swap chain of a window's own
surface, and with DirectComposition the starter vanished a few seconds
after its window came up on a Windows 10 machine with a GTX 1650, without
a word in its log, under Steam or started on its own. With
--software-render it stayed.

The processor now draws every window on Windows, and each frame is copied
into its window by GDI: no composition visual, no swap chain for an
overlay to hook. On X11 the graphics card still draws, and
--software-render still asks the processor there.
2026-12-02 18:54:12 +01:00
10 changed files with 36 additions and 124 deletions
+9 -5
View File
@@ -14,7 +14,7 @@ public class SoftwareRenderTests
} }
[Fact] [Fact]
public void Without_the_switch_the_graphics_card_draws() public void Without_the_switch_it_is_not_asked_for()
{ {
Assert.False(SoftwareRender.AskedIn(Array.Empty<string>())); Assert.False(SoftwareRender.AskedIn(Array.Empty<string>()));
Assert.False(SoftwareRender.AskedIn(new[] { "--software" })); Assert.False(SoftwareRender.AskedIn(new[] { "--software" }));
@@ -25,21 +25,25 @@ public class SoftwareRenderTests
{ {
var options = SoftwareRender.Win32Options; var options = SoftwareRender.Win32Options;
// No WinUI composition, DirectComposition or swap chain of the graphics card's.
Assert.Equal(new[] { Win32RenderingMode.Software }, options.RenderingMode); Assert.Equal(new[] { Win32RenderingMode.Software }, options.RenderingMode);
Assert.Equal(new[] { Win32CompositionMode.RedirectionSurface }, options.CompositionMode); Assert.Equal(new[] { Win32CompositionMode.RedirectionSurface }, options.CompositionMode);
} }
[Fact] [Fact]
public void X11_draws_on_the_processor() public void X11_draws_on_the_processor_when_asked()
{ {
Assert.Equal(new[] { X11RenderingMode.Software }, SoftwareRender.X11Options.RenderingMode); Assert.Equal(new[] { X11RenderingMode.Software }, SoftwareRender.X11Options.RenderingMode);
} }
[Fact] [Theory]
public void Both_platforms_options_go_to_the_same_builder() [InlineData(false)]
[InlineData(true)]
public void The_options_go_to_the_same_builder_with_or_without_the_switch(bool asked)
{ {
var builder = AppBuilder.Configure<Avalonia.Application>(); var builder = AppBuilder.Configure<Avalonia.Application>();
string[] args = asked ? new[] { SoftwareRender.Switch } : Array.Empty<string>();
Assert.Same(builder, SoftwareRender.ApplyTo(builder)); Assert.Same(builder, SoftwareRender.ApplyTo(builder, args));
} }
} }
-14
View File
@@ -79,20 +79,6 @@ public class TrainsetDisplayTests
Assert.True(TrainsetDisplay.StartableIn(decor, Mode(advanced: true))); Assert.True(TrainsetDisplay.StartableIn(decor, Mode(advanced: true)));
} }
[Fact]
public void The_standard_mode_changes_the_crew_but_not_in_the_simulators_own_consists()
{
var standard = Mode(advanced: false);
var decor = new Trainset("trainset a tor 0 0 //$decor\nnode -1 0 v1 dynamic d s m 0 headdriver 3 0 enddynamic\nendtrainset");
Assert.True(TrainsetDisplay.CrewEditableIn(Consist(), standard));
Assert.True(TrainsetDisplay.CrewEditableIn(Consist(driver: "nobody"), standard));
Assert.True(TrainsetDisplay.CrewEditableIn(null, standard));
Assert.False(TrainsetDisplay.CrewEditableIn(Consist(description: "-ai"), standard));
Assert.False(TrainsetDisplay.CrewEditableIn(decor, standard));
Assert.True(TrainsetDisplay.CrewEditableIn(Consist(description: "-ai"), Mode(advanced: true)));
}
[Fact] [Fact]
public void The_filters_work_in_the_advanced_mode() public void The_filters_work_in_the_advanced_mode()
{ {
-46
View File
@@ -1,46 +0,0 @@
using Avalonia;
using StarterNG.Infrastructure;
namespace StarterNG.Tests;
public class WindowSurfacesTests
{
[Fact]
public void Windows_draws_into_a_directcomposition_surface_and_never_through_winui_composition()
{
var options = WindowSurfaces.Win32Options;
Assert.Equal(Win32CompositionMode.DirectComposition, options.CompositionMode.First());
Assert.DoesNotContain(Win32CompositionMode.WinUIComposition, options.CompositionMode);
}
[Fact]
public void The_window_surface_is_only_the_fallback()
{
// There ANGLE presents through a swap chain, and the Steam overlay draws over it.
Assert.Equal(Win32CompositionMode.RedirectionSurface, WindowSurfaces.Win32Options.CompositionMode.Last());
}
[Fact]
public void No_swap_chain_of_its_own_is_asked_for()
{
Assert.DoesNotContain(Win32CompositionMode.LowLatencyDxgiSwapChain, WindowSurfaces.Win32Options.CompositionMode);
}
[Fact]
public void The_graphics_card_still_draws()
{
Assert.Equal(new Win32PlatformOptions().RenderingMode, WindowSurfaces.Win32Options.RenderingMode);
Assert.Contains(Win32RenderingMode.AngleEgl, WindowSurfaces.Win32Options.RenderingMode);
}
[Theory]
[InlineData(false)]
[InlineData(true)]
public void The_options_go_to_the_same_builder_with_or_without_the_processor(bool softwareRender)
{
var builder = AppBuilder.Configure<Avalonia.Application>();
Assert.Same(builder, WindowSurfaces.ApplyTo(builder, softwareRender));
}
}
-8
View File
@@ -52,14 +52,6 @@ public static class TrainsetDisplay
public static bool StartableIn(Trainset trainset, SimulatorSettings settings) => public static bool StartableIn(Trainset trainset, SimulatorSettings settings) =>
settings.AdvancedSettings || (!IsAi(trainset) && !trainset.Decor); settings.AdvancedSettings || (!IsAi(trainset) && !trainset.Decor);
/// <summary>
/// Whether the crew of the consist being edited may be changed: in the standard mode
/// only in one the player may start in - the simulator's own consists and the
/// decorations keep the crew the scenario gave them.
/// </summary>
public static bool CrewEditableIn(Trainset? trainset, SimulatorSettings settings) =>
trainset is null || StartableIn(trainset, settings);
/// <summary>The consist's row in those lists: what it is made of, or the track of one with nothing on it.</summary> /// <summary>The consist's row in those lists: what it is made of, or the track of one with nothing on it.</summary>
public static string ListLabel(Trainset trainset) => public static string ListLabel(Trainset trainset) =>
CompositionText(trainset) ?? string.Format(App.Loc["EmptyTrainset"], trainset.Track ?? ""); CompositionText(trainset) ?? string.Format(App.Loc["EmptyTrainset"], trainset.Track ?? "");
+14 -4
View File
@@ -6,8 +6,15 @@ using Avalonia;
namespace StarterNG.Infrastructure; namespace StarterNG.Infrastructure;
/// <summary> /// <summary>
/// Drawn by the processor instead of the graphics card, for a machine on which the /// On Windows the processor draws the starter's windows, and each frame is copied into its window
/// window comes up empty. Each platform reads only its own options, so both are given. /// by GDI. Every way of the graphics card's failed on some machine: Avalonia's WinUI composition
/// visual left windows black on Windows 11 25H2, the Steam overlay drew its frame counter over a
/// window's own swap chain, and with DirectComposition the starter vanished a few seconds after its
/// window came up on a Windows 10 machine with a GTX 1650, without a word in its log. A frame copied
/// by GDI has no swap chain for an overlay to hook, and lists, text and pictures are no work for the
/// processor.
/// On X11 the graphics card draws, unless <see cref="Switch"/> asks the processor, for a machine on
/// which the window comes up empty. Each platform reads only its own options.
/// </summary> /// </summary>
public static class SoftwareRender public static class SoftwareRender
{ {
@@ -27,6 +34,9 @@ public static class SoftwareRender
RenderingMode = new[] { X11RenderingMode.Software } RenderingMode = new[] { X11RenderingMode.Software }
}; };
public static AppBuilder ApplyTo(AppBuilder builder) => public static AppBuilder ApplyTo(AppBuilder builder, IEnumerable<string> args)
builder.With(Win32Options).With(X11Options); {
builder.With(Win32Options);
return AskedIn(args) ? builder.With(X11Options) : builder;
}
} }
@@ -1,32 +0,0 @@
using Avalonia;
namespace StarterNG.Infrastructure;
/// <summary>
/// On Windows the graphics card draws each window of the starter into a DirectComposition
/// surface, not into Avalonia's default WinUI composition visual. On Windows 11 25H2 that
/// visual was left empty on many starts: the main window, or a dialog opened later,
/// stayed black while the others drew, and came back only now and then.
/// The window's own redirection surface is only the fallback: there ANGLE draws through a
/// swap chain of the window, and the Steam overlay, which Steam puts into the starter as
/// the game it launches, hooks that swap chain's Present and draws its frame counter and
/// notifications over the starter. A composition surface is drawn without a Present.
/// </summary>
public static class WindowSurfaces
{
public static Win32PlatformOptions Win32Options => new()
{
CompositionMode = new[]
{
Win32CompositionMode.DirectComposition,
Win32CompositionMode.RedirectionSurface
}
};
/// <summary>
/// The options a platform reads are the last given, so the processor, when asked
/// for, draws with <see cref="SoftwareRender"/>'s own and these are left out.
/// </summary>
public static AppBuilder ApplyTo(AppBuilder builder, bool softwareRender) =>
softwareRender ? SoftwareRender.ApplyTo(builder) : builder.With(Win32Options);
}
+7 -6
View File
@@ -10,7 +10,8 @@ namespace StarterNG;
static class Program static class Program
{ {
private static bool _softwareRender; // What --software-render is looked for in; none for the designer, which calls BuildAvaloniaApp itself.
private static string[] _args = Array.Empty<string>();
[STAThread] [STAThread]
public static void Main(string[] args) public static void Main(string[] args)
@@ -19,7 +20,7 @@ static class Program
var graphics = SystemGraphicsLibraries.TakeOnWindows(); var graphics = SystemGraphicsLibraries.TakeOnWindows();
graphics?.ServeTo(typeof(Win32PlatformOptions).Assembly); graphics?.ServeTo(typeof(Win32PlatformOptions).Assembly);
_softwareRender = SoftwareRender.AskedIn(args); _args = args;
// Composition root first: everything below, including the crash handlers, // Composition root first: everything below, including the crash handlers,
// resolves its collaborators from this graph. // resolves its collaborators from this graph.
@@ -73,14 +74,14 @@ static class Program
}; };
} }
// Without the switch the graphics card draws, into the window surfaces. // On Windows the processor draws; on X11 the graphics card, unless --software-render.
private static AppBuilder WithSoftwareRenderIfAsked(this AppBuilder builder) => private static AppBuilder WithSoftwareRender(this AppBuilder builder) =>
WindowSurfaces.ApplyTo(builder, _softwareRender); SoftwareRender.ApplyTo(builder, _args);
public static AppBuilder BuildAvaloniaApp() public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>() => AppBuilder.Configure<App>()
.UsePlatformDetect() .UsePlatformDetect()
.WithSoftwareRenderIfAsked() .WithSoftwareRender()
.WithInterFont() .WithInterFont()
.WithDiagnosticsLogging() .WithDiagnosticsLogging()
.AfterSetup(_ => LogUiExceptions()); .AfterSetup(_ => LogUiExceptions());
+1 -1
View File
@@ -69,7 +69,7 @@ public partial class Depot : UserControl
if (Design.IsDesignMode) if (Design.IsDesignMode)
return; return;
// The standard mode lists other consists and leaves the crew of the simulator's own alone. // The standard mode lists other consists and leaves the crew alone.
Settings.AdvancedModeChanged += () => Settings.AdvancedModeChanged += () =>
{ {
PopulateSceneryConsists(); PopulateSceneryConsists();
+3 -6
View File
@@ -49,9 +49,6 @@ public sealed class VehicleCards
public Dynamic? PressedCar { get; set; } public Dynamic? PressedCar { get; set; }
private bool CrewEditable =>
TrainsetDisplay.CrewEditableIn(_consist.EditingTrainset, AppServices.Current.Settings);
public VehicleCards(Panel consistStack, VehicleCatalog db, Consist consist, public VehicleCards(Panel consistStack, VehicleCatalog db, Consist consist,
Cargo cargo, MiniTextures minis, Cursor hand, Cargo cargo, MiniTextures minis, Cursor hand,
Action redraw, Action refreshDetails, Action<Dynamic> selectInBrowser, Action redraw, Action refreshDetails, Action<Dynamic> selectInBrowser,
@@ -120,8 +117,8 @@ public sealed class VehicleCards
HorizontalAlignment = HorizontalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center,
Margin = new Thickness(0, 1, 0, 2) Margin = new Thickness(0, 1, 0, 2)
}; };
// Who sits in the cab; in the standard mode not in the simulator's own consists. // Who sits in the cab - the player, the simulator, a passenger or nobody - is for the advanced mode.
if (CrewEditable) if (AppServices.Current.Settings.AdvancedSettings)
controls.Children.Add(DriverButton(item)); controls.Children.Add(DriverButton(item));
controls.Children.Add(FlipButton(item)); controls.Children.Add(FlipButton(item));
@@ -698,7 +695,7 @@ public sealed class VehicleCards
else if (_consist.CanJoin(item, index)) else if (_consist.CanJoin(item, index))
menu.AddItem(App.Loc["TipJoin"], () => _consist.Join(item)); menu.AddItem(App.Loc["TipJoin"], () => _consist.Join(item));
if (CrewEditable) if (AppServices.Current.Settings.AdvancedSettings)
{ {
var crew = new MenuItem { Header = App.Loc["CrewLabel"] }; var crew = new MenuItem { Header = App.Loc["CrewLabel"] };
foreach (var (type, key) in CrewChoices.All) foreach (var (type, key) in CrewChoices.All)
+2 -2
View File
@@ -280,8 +280,8 @@ public sealed class VehicleDetails
}; };
driver.MinWidth = 0; driver.MinWidth = 0;
driver.HorizontalAlignment = HorizontalAlignment.Stretch; driver.HorizontalAlignment = HorizontalAlignment.Stretch;
// Shown but not changed in the standard mode in the simulator's own consists. // Shown but not changed in the standard mode: who drives is for the advanced one.
driver.IsEnabled = TrainsetDisplay.CrewEditableIn(_consist.EditingTrainset, AppServices.Current.Settings); driver.IsEnabled = AppServices.Current.Settings.AdvancedSettings;
var rows = new StackPanel(); var rows = new StackPanel();
rows.Children.Add(Row(App.Loc["CrewLabel"], driver)); rows.Children.Add(Row(App.Loc["CrewLabel"], driver));