From ba8cf49159f5048f6b08214988819310ec7356c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=83=E4=B9=8B=E7=99=BD=E7=99=BD?= Date: Mon, 15 Jul 2024 15:31:43 +0800 Subject: [PATCH] Fix: crash (#91) Co-authored-by: yvanpeng --- Lemon/Info.plist | 2 +- localPod/LemonStat/LemonStat/Classes/src/McGpuInfo.m | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Lemon/Info.plist b/Lemon/Info.plist index cf356e2ca..cafeda9f9 100644 --- a/Lemon/Info.plist +++ b/Lemon/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 5.1.9 CFBundleVersion - 1018 + 1019 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSAppTransportSecurity diff --git a/localPod/LemonStat/LemonStat/Classes/src/McGpuInfo.m b/localPod/LemonStat/LemonStat/Classes/src/McGpuInfo.m index 72e91579d..ff2730c27 100644 --- a/localPod/LemonStat/LemonStat/Classes/src/McGpuInfo.m +++ b/localPod/LemonStat/LemonStat/Classes/src/McGpuInfo.m @@ -38,20 +38,24 @@ - (void)updateInfoIOService { } NSNumber *utilization = stats[@"Device Utilization %"]; - if (!utilization) { + if (![utilization isKindOfClass:NSNumber.class]) { utilization = stats[@"GPU Activity(%)"]; } - if (!utilization) { + if (![utilization isKindOfClass:NSNumber.class]) { continue; } // IOKit 框架定义的标识符属性 - NSInteger IOVARendererID = [dict[@"IOVARendererID"] longValue]; + NSNumber *IOVARendererID = dict[@"IOVARendererID"]; + NSInteger ID = 0; + if ([IOVARendererID isKindOfClass:NSNumber.class]) { + ID = [IOVARendererID longValue]; + } CGFloat usage = [utilization longValue] / 100.0; usage = fmaxf(0.0, fminf(usage, 1.0)); McGpuCore *gpuCore = [[McGpuCore alloc] init]; - gpuCore.ID = IOVARendererID; + gpuCore.ID = ID; gpuCore.usage = usage; [mutableCores addObject:gpuCore];