Skip to content

Commit

Permalink
Changed: Correctly interpret HRESULT
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Jun 19, 2024
1 parent ec04ffa commit 2873249
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ internal unsafe class DirectXUnmanagedMethods
[DllImport("user32", ExactSpelling = true)]
internal static extern bool EnumDisplaySettingsW(ushort* lpszDeviceName, uint iModeNum, DEVMODEW* lpDevMode);

// Note (Exact return type is HRESULT which is a 32-bit integer on all platforms)
[DllImport("d3d11", ExactSpelling = true)]
public static extern int D3D11CreateDevice(
IntPtr adapter, D3D_DRIVER_TYPE DriverType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Avalonia.OpenGL.Angle;
using Avalonia.OpenGL.Egl;
using Avalonia.Win32.DirectX;
using Avalonia.Win32.Interop;
using MicroCom.Runtime;
using static Avalonia.OpenGL.Egl.EglConsts;
// ReSharper disable SimplifyLinqExpressionUseMinByAndMaxBy
Expand Down Expand Up @@ -178,7 +179,7 @@ private static unsafe IntPtr CreateD3D11Device(IDXGIAdapter1? chosenAdapter, D3D
IntPtr.Zero, 0, featureLevels, (uint)featureLevels.Length,
7, out var pD3dDevice, out _, null);

if (hr == 0)
if (hr >= 0) // SUCCEEDED(hr)
return pD3dDevice;

// Otherwise fallback to legacy software device.
Expand All @@ -192,7 +193,7 @@ void LogCannotCreateDevice(D3D_DRIVER_TYPE type, int hresult)
IntPtr.Zero, 0, featureLevels, (uint)featureLevels.Length,
7, out pD3dDevice, out _, null);

if (hr == 0)
if (hr >= 0)
return pD3dDevice;

// As a last resort, try creating an unknown device.
Expand All @@ -205,7 +206,7 @@ void LogCannotCreateDevice(D3D_DRIVER_TYPE type, int hresult)
IntPtr.Zero, 0, featureLevels, (uint)featureLevels.Length,
7, out pD3dDevice, out _, null);

if (hr != 0)
if (hr < 0) // FAILED(hr)
LogCannotCreateDevice(D3D_DRIVER_TYPE.D3D_DRIVER_TYPE_UNKNOWN, hr);

return pD3dDevice;
Expand Down

0 comments on commit 2873249

Please sign in to comment.