From 8b8ce501d431797ad06d1d660cb933beeb058f7b Mon Sep 17 00:00:00 2001 From: scorpion-26 Date: Mon, 6 Nov 2023 20:16:51 +0100 Subject: [PATCH] Add nullptr check for batteryText If SensorTooltips: true, then batteryText would be nullptr, but the class would still be updated, causing the crash Fixes https://github.com/scorpion-26/gBar/issues/58 --- src/Bar.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Bar.cpp b/src/Bar.cpp index 0f6052c..cbeb734 100644 --- a/src/Bar.cpp +++ b/src/Bar.cpp @@ -24,6 +24,7 @@ namespace Bar case Right: return Alignment::Right; case Center: return Alignment::Fill; } + return Alignment::Right; } TransitionType SideToDefaultTransition(Side side) @@ -94,13 +95,15 @@ namespace Bar if (isCharging && !wasCharging && sensor.Get() != nullptr) { sensor.AddClass("battery-charging"); - batteryText->AddClass("battery-charging"); + if (batteryText) + batteryText->AddClass("battery-charging"); wasCharging = true; } else if (!isCharging && wasCharging) { sensor.RemoveClass("battery-charging"); - batteryText->RemoveClass("battery-charging"); + if (batteryText) + batteryText->RemoveClass("battery-charging"); wasCharging = false; } return TimerResult::Ok;