Skip to content

Commit

Permalink
Merge pull request #7310 from odalet/feature/fix-7309
Browse files Browse the repository at this point in the history
Fixes #7309 - Each time we retrieve a null *PlatformOptions from AvaloniaLocator, return a default instance
  • Loading branch information
danwalmsley authored Jan 4, 2022
2 parents 907a18d + c73a6c8 commit a9077b7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/Avalonia.Native/AvaloniaNativeMenuExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ private NativeMenu CreateDefaultAppMenu()
};
result.Add(aboutItem);

var macOpts = AvaloniaLocator.Current.GetService<MacOSPlatformOptions>();
if (macOpts == null || !macOpts.DisableDefaultApplicationMenuItems)
var macOpts = AvaloniaLocator.Current.GetService<MacOSPlatformOptions>() ?? new MacOSPlatformOptions();
if (!macOpts.DisableDefaultApplicationMenuItems)
{
result.Add(new NativeMenuItemSeparator());

Expand Down Expand Up @@ -142,9 +142,9 @@ private NativeMenu CreateDefaultAppMenu()

private void DoLayoutReset(bool forceUpdate = false)
{
var macOpts = AvaloniaLocator.Current.GetService<MacOSPlatformOptions>();
var macOpts = AvaloniaLocator.Current.GetService<MacOSPlatformOptions>() ?? new MacOSPlatformOptions();

if (macOpts != null && macOpts.DisableNativeMenus)
if (macOpts.DisableNativeMenus)
{
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Avalonia.Native/AvaloniaNativePlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ void DoInitialize(AvaloniaNativePlatformOptions options)
_factory.Initialize(new GCHandleDeallocator(), applicationPlatform);
if (_factory.MacOptions != null)
{
var macOpts = AvaloniaLocator.Current.GetService<MacOSPlatformOptions>();
var macOpts = AvaloniaLocator.Current.GetService<MacOSPlatformOptions>() ?? new MacOSPlatformOptions();

_factory.MacOptions.SetShowInDock(macOpts?.ShowInDock != false ? 1 : 0);
_factory.MacOptions.SetShowInDock(macOpts.ShowInDock ? 1 : 0);
}

AvaloniaLocator.CurrentMutable
Expand Down
4 changes: 2 additions & 2 deletions src/Avalonia.X11/Glx/GlxDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public GlxDisplay(X11Info x11, IList<GlVersion> probeProfiles)

if (Environment.GetEnvironmentVariable("AVALONIA_GLX_IGNORE_RENDERER_BLACKLIST") != "1")
{
var blacklist = AvaloniaLocator.Current.GetService<X11PlatformOptions>()
?.GlxRendererBlacklist;
var opts = AvaloniaLocator.Current.GetService<X11PlatformOptions>() ?? new X11PlatformOptions();
var blacklist = opts.GlxRendererBlacklist;
if (blacklist != null)
foreach (var item in blacklist)
if (glInterface.Renderer.Contains(item))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ void Initialize()
if (_fb is IGlOutputBackend gl)
AvaloniaLocator.CurrentMutable.Bind<IPlatformOpenGlInterface>().ToConstant(gl.PlatformOpenGlInterface);

var opts = AvaloniaLocator.Current.GetService<LinuxFramebufferPlatformOptions>();
var opts = AvaloniaLocator.Current.GetService<LinuxFramebufferPlatformOptions>() ?? new LinuxFramebufferPlatformOptions();

AvaloniaLocator.CurrentMutable
.Bind<IPlatformThreadingInterface>().ToConstant(Threading)
.Bind<IRenderTimer>().ToConstant(new DefaultRenderTimer(opts?.Fps ?? 60))
.Bind<IRenderTimer>().ToConstant(new DefaultRenderTimer(opts.Fps))
.Bind<IRenderLoop>().ToConstant(new RenderLoop())
.Bind<ICursorFactory>().ToTransient<CursorFactoryStub>()
.Bind<IKeyboardDevice>().ToConstant(new KeyboardDevice())
Expand Down
9 changes: 4 additions & 5 deletions src/Windows/Avalonia.Win32/Win32GlManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@ public static void Initialize()
{
AvaloniaLocator.CurrentMutable.Bind<IPlatformOpenGlInterface>().ToLazy<IPlatformOpenGlInterface>(() =>
{
var opts = AvaloniaLocator.Current.GetService<Win32PlatformOptions>();
if (opts?.UseWgl == true)
var opts = AvaloniaLocator.Current.GetService<Win32PlatformOptions>() ?? new Win32PlatformOptions();
if (opts.UseWgl)
{
var wgl = WglPlatformOpenGlInterface.TryCreate();
return wgl;
}
if (opts?.AllowEglInitialization ?? Win32Platform.WindowsVersion > PlatformConstants.Windows7)
if (opts.AllowEglInitialization ?? Win32Platform.WindowsVersion > PlatformConstants.Windows7)
{
var egl = EglPlatformOpenGlInterface.TryCreate(() => new AngleWin32EglDisplay());
if (egl != null &&
opts?.UseWindowsUIComposition == true)
if (egl != null && opts.UseWindowsUIComposition)
{
WinUICompositorConnection.TryCreateAndRegister(egl, opts.CompositionBackdropCornerRadius);
}
Expand Down

0 comments on commit a9077b7

Please sign in to comment.