1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-12-25 07:09:55 +02:00

Don't crash if battery icon is not found

The icon pointer can be null, so don't convert it to a reference.
This commit is contained in:
Maarten ter Huurne 2015-04-21 19:29:26 +02:00
parent 9cfbc56bfa
commit 05a58e869c
3 changed files with 7 additions and 4 deletions

View File

@ -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) {

View File

@ -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()

View File

@ -17,7 +17,7 @@ public:
/**
* Gets the icon that reflects the current battery status.
*/
OffscreenSurface const& getIcon();
const OffscreenSurface *getIcon();
private:
void update();