From fd787e853331c608045d95b1b59be56742a6e06e Mon Sep 17 00:00:00 2001 From: Natsumi Date: Sun, 17 Mar 2024 05:21:53 +1300 Subject: [PATCH] Fix uptime crash --- Dotnet/AppApi/AppApiVr.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Dotnet/AppApi/AppApiVr.cs b/Dotnet/AppApi/AppApiVr.cs index a4f611ab..1a04a27e 100644 --- a/Dotnet/AppApi/AppApiVr.cs +++ b/Dotnet/AppApi/AppApiVr.cs @@ -8,12 +8,20 @@ namespace VRCX public class AppApiVr { public static readonly AppApiVr Instance; - - private readonly PerformanceCounter _uptime = new PerformanceCounter("System", "System Up Time"); + private static readonly PerformanceCounter Uptime; static AppApiVr() { Instance = new AppApiVr(); + + try + { + Uptime = new PerformanceCounter("System", "System Up Time"); + } + catch + { + Uptime = null; + } } public void VrInit() @@ -47,8 +55,11 @@ namespace VRCX /// The number of milliseconds that the system has been running. public double GetUptime() { - _uptime.NextValue(); - return TimeSpan.FromSeconds(_uptime.NextValue()).TotalMilliseconds; + if (Uptime == null) + return 0; + + Uptime.NextValue(); + return TimeSpan.FromSeconds(Uptime.NextValue()).TotalMilliseconds; } ///