From 59bd626aefd8086071bd1215daed41d33163f0eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=B6ller?= Date: Tue, 25 Feb 2020 19:11:55 +0100 Subject: [PATCH] Fixed a NullReferenceException in the AMD17CPU.Update method. --- Hardware/CPU/AMD17CPU.cs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/Hardware/CPU/AMD17CPU.cs b/Hardware/CPU/AMD17CPU.cs index fda2c47..b49a678 100644 --- a/Hardware/CPU/AMD17CPU.cs +++ b/Hardware/CPU/AMD17CPU.cs @@ -111,10 +111,9 @@ namespace OpenHardwareMonitor.Hardware.CPU { "CPU Package", 0, SensorType.Power, this, settings); ActivateSensor(packagePowerSensor); } - - coresPowerSensor = new Sensor("CPU Cores", 1, SensorType.Power, this, - settings); } + coresPowerSensor = new Sensor("CPU Cores", 1, SensorType.Power, this, + settings); busClock = new Sensor("Bus Speed", 0, SensorType.Clock, this, settings); timeStampCounterMultiplier = GetTimeStampCounterMultiplier(); @@ -236,8 +235,9 @@ namespace OpenHardwareMonitor.Hardware.CPU { ActivateSensor(ccdAvgTemperature); } - if (Ring0.Rdmsr(MSR_PKG_ENERGY_STAT, out uint energyConsumed, out _)) { - + if (energyUnitMultiplier != 0 && + Ring0.Rdmsr(MSR_PKG_ENERGY_STAT, out uint energyConsumed, out _)) + { DateTime time = DateTime.UtcNow; float deltaTime = (float)(time - lastEnergyTime).TotalSeconds; if (deltaTime > 0.01) { @@ -318,14 +318,16 @@ namespace OpenHardwareMonitor.Hardware.CPU { multiplier = GetMultiplier(); ThreadAffinity.Set(mask); - - float deltaTime = (float)(energyTime - lastEnergyTime).TotalSeconds; - if (deltaTime > 0.01) { - power = cpu.energyUnitMultiplier * - unchecked(energyConsumed - lastEnergyConsumed) / deltaTime; - powerSensor.Value = power; - lastEnergyTime = energyTime; - lastEnergyConsumed = energyConsumed; + + if (cpu.energyUnitMultiplier != 0) { + float deltaTime = (float)(energyTime - lastEnergyTime).TotalSeconds; + if (deltaTime > 0.01) { + power = cpu.energyUnitMultiplier * + unchecked(energyConsumed - lastEnergyConsumed) / deltaTime; + powerSensor.Value = power; + lastEnergyTime = energyTime; + lastEnergyConsumed = energyConsumed; + } } if (multiplier.HasValue) {