Skip to content

Commit c14ab62

Browse files
authored
Merge pull request LykosAI#415 from ionite34/fix-memoryinfo
2 parents 9b16171 + b5dc963 commit c14ab62

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2
88
## v2.7.3
99
### Fixed
1010
- Fixed UnicodeDecodeError when using extra_model_paths.yaml in ComfyUI on certain locales
11+
- Fixed [#334](https://github.com/LykosAI/StabilityMatrix/issues/334) - Win32Exception if Settings are opened
1112

1213
## v2.7.2
1314
### Changed

StabilityMatrix.Avalonia/ViewModels/Settings/MainSettingsViewModel.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ public override void OnLoaded()
212212
base.OnLoaded();
213213

214214
hardwareInfoUpdateTimer.Start();
215-
OnHardwareInfoUpdateTimerTick(null, null!);
216215
}
217216

218217
/// <inheritdoc />
@@ -236,7 +235,10 @@ public override async Task OnLoadedAsync()
236235

237236
private void OnHardwareInfoUpdateTimerTick(object? sender, EventArgs e)
238237
{
239-
MemoryInfo = HardwareHelper.GetMemoryInfo();
238+
if (HardwareHelper.IsMemoryInfoAvailable && HardwareHelper.TryGetMemoryInfo(out var newMemoryInfo))
239+
{
240+
MemoryInfo = newMemoryInfo;
241+
}
240242
}
241243

242244
partial void OnSelectedThemeChanged(string? value)

StabilityMatrix.Core/Helper/HardwareInfo/HardwareHelper.cs

+22
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
using System.Text.RegularExpressions;
66
using Hardware.Info;
77
using Microsoft.Win32;
8+
using NLog;
89

910
namespace StabilityMatrix.Core.Helper.HardwareInfo;
1011

1112
public static partial class HardwareHelper
1213
{
14+
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
15+
1316
private static IReadOnlyList<GpuInfo>? cachedGpuInfos;
1417

1518
private static readonly Lazy<IHardwareInfo> HardwareInfoLazy = new(() => new Hardware.Info.HardwareInfo());
@@ -149,6 +152,25 @@ public static bool HasAmdGpu()
149152
// Set DirectML for default if AMD and Windows
150153
public static bool PreferDirectML() => !HasNvidiaGpu() && HasAmdGpu() && Compat.IsWindows;
151154

155+
private static readonly Lazy<bool> IsMemoryInfoAvailableLazy = new(() => TryGetMemoryInfo(out _));
156+
public static bool IsMemoryInfoAvailable => IsMemoryInfoAvailableLazy.Value;
157+
158+
public static bool TryGetMemoryInfo(out MemoryInfo memoryInfo)
159+
{
160+
try
161+
{
162+
memoryInfo = GetMemoryInfo();
163+
return true;
164+
}
165+
catch (Exception ex)
166+
{
167+
Logger.Warn(ex, "Failed to get memory info");
168+
169+
memoryInfo = default;
170+
return false;
171+
}
172+
}
173+
152174
/// <summary>
153175
/// Gets the total and available physical memory in bytes.
154176
/// </summary>

0 commit comments

Comments
 (0)