Fixed an InvalidOperationException in OpenHardwareMonitor.GUI.SensorGadget.OnPaint caused by sensors with null as value.
1.1 --- a/GUI/SensorGadget.cs Wed Sep 15 18:43:15 2010 +0000
1.2 +++ b/GUI/SensorGadget.cs Fri Sep 17 18:32:11 2010 +0000
1.3 @@ -423,52 +423,57 @@
1.4 foreach (ISensor sensor in pair.Value) {
1.5 int remainingWidth;
1.6
1.7 - if (sensor.SensorType != SensorType.Load &&
1.8 - sensor.SensorType != SensorType.Control)
1.9 +
1.10 + if ((sensor.SensorType != SensorType.Load &&
1.11 + sensor.SensorType != SensorType.Control) || !sensor.Value.HasValue)
1.12 {
1.13 - string format = "";
1.14 - switch (sensor.SensorType) {
1.15 - case SensorType.Voltage:
1.16 - format = "{0:F2} V";
1.17 - break;
1.18 - case SensorType.Clock:
1.19 - format = "{0:F0} MHz";
1.20 - break;
1.21 - case SensorType.Temperature:
1.22 - format = "{0:F1} °C";
1.23 - break;
1.24 - case SensorType.Fan:
1.25 - format = "{0:F0} RPM";
1.26 - break;
1.27 - case SensorType.Flow:
1.28 - format = "{0:F0} L/h";
1.29 - break;
1.30 + string formatted;
1.31 +
1.32 + if (sensor.Value.HasValue) {
1.33 + string format = "";
1.34 + switch (sensor.SensorType) {
1.35 + case SensorType.Voltage:
1.36 + format = "{0:F2} V";
1.37 + break;
1.38 + case SensorType.Clock:
1.39 + format = "{0:F0} MHz";
1.40 + break;
1.41 + case SensorType.Temperature:
1.42 + format = "{0:F1} °C";
1.43 + break;
1.44 + case SensorType.Fan:
1.45 + format = "{0:F0} RPM";
1.46 + break;
1.47 + case SensorType.Flow:
1.48 + format = "{0:F0} L/h";
1.49 + break;
1.50 + }
1.51 +
1.52 + if (sensor.SensorType == SensorType.Temperature &&
1.53 + unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit) {
1.54 + formatted = string.Format("{0:F1} °F",
1.55 + sensor.Value * 1.8 + 32);
1.56 + } else {
1.57 + formatted = string.Format(format, sensor.Value);
1.58 + }
1.59 + } else {
1.60 + formatted = "-";
1.61 }
1.62
1.63 - string formattedValue;
1.64 - if (sensor.SensorType == SensorType.Temperature &&
1.65 - unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit) {
1.66 - formattedValue = string.Format("{0:F1} °F",
1.67 - sensor.Value * 1.8 + 32);
1.68 - } else {
1.69 - formattedValue = string.Format(format, sensor.Value);
1.70 - }
1.71 -
1.72 -
1.73 - g.DrawString(formattedValue, smallFont, darkWhite,
1.74 - new RectangleF(-1, y - 1, w - rightMargin + 3, 0),
1.75 + g.DrawString(formatted, smallFont, darkWhite,
1.76 + new RectangleF(-1, y - 1, w - rightMargin + 3, 0),
1.77 alignRightStringFormat);
1.78
1.79 - remainingWidth = w - (int)Math.Floor(g.MeasureString(formattedValue,
1.80 - smallFont, w, StringFormat.GenericTypographic).Width) -
1.81 + remainingWidth = w - (int)Math.Floor(g.MeasureString(formatted,
1.82 + smallFont, w, StringFormat.GenericTypographic).Width) -
1.83 rightMargin;
1.84 - } else {
1.85 - DrawProgress(g, w - progressWidth - rightMargin,
1.86 + } else {
1.87 + DrawProgress(g, w - progressWidth - rightMargin,
1.88 y + 4, progressWidth, 6, 0.01f * sensor.Value.Value);
1.89
1.90 remainingWidth = w - progressWidth - rightMargin;
1.91 }
1.92 -
1.93 +
1.94 remainingWidth -= leftMargin + 2;
1.95 if (remainingWidth > 0) {
1.96 g.DrawString(sensor.Name, smallFont, darkWhite,