From 05a58e869c2eb7d77b6c229ba83850ae1d35eaf1 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Tue, 21 Apr 2015 19:29:26 +0200 Subject: [PATCH] Don't crash if battery icon is not found The icon pointer can be null, so don't convert it to a reference. --- src/background.cpp | 5 ++++- src/battery.cpp | 4 ++-- src/battery.h | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/background.cpp b/src/background.cpp index bfec8ea..7162a41 100644 --- a/src/background.cpp +++ b/src/background.cpp @@ -22,7 +22,10 @@ void Background::paint(Surface& s) { s.width() / 2, gmenu2x.bottomBarTextY, Font::HAlignCenter, Font::VAlignMiddle); - battery.getIcon().blit(s, s.width() - 19, gmenu2x.bottomBarIconY); + auto icon = battery.getIcon(); + if (icon) { + icon->blit(s, s.width() - 19, gmenu2x.bottomBarIconY); + } } bool Background::handleButtonPress(InputManager::Button button) { diff --git a/src/battery.cpp b/src/battery.cpp index 404f90f..5c9b6be 100644 --- a/src/battery.cpp +++ b/src/battery.cpp @@ -53,7 +53,7 @@ Battery::Battery(SurfaceCollection& sc_) update(); } -OffscreenSurface const& Battery::getIcon() +const OffscreenSurface *Battery::getIcon() { // Check battery status every 60 seconds. unsigned int now = SDL_GetTicks(); @@ -62,7 +62,7 @@ OffscreenSurface const& Battery::getIcon() update(); } - return *sc.skinRes(iconPath); + return sc.skinRes(iconPath); } void Battery::update() diff --git a/src/battery.h b/src/battery.h index 90d7ea0..443bb9f 100644 --- a/src/battery.h +++ b/src/battery.h @@ -17,7 +17,7 @@ public: /** * Gets the icon that reflects the current battery status. */ - OffscreenSurface const& getIcon(); + const OffscreenSurface *getIcon(); private: void update();