Skip to content

Commit

Permalink
Fix nullptr crash in player status hud due to wrong player item pocke…
Browse files Browse the repository at this point in the history
…t access (#3119)

Fixes a crash if multiple players are in the game and the first player does not have any bonus while other players have a bonus. Due to a wrong access of m_bonus_sprites, a nullptr is returned for the sprite pointer which causes a segfault when the hud tries to draw the sprite.
  • Loading branch information
Brockengespenst authored Dec 2, 2024
1 parent b776feb commit cb5116a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/supertux/player_status_hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ PlayerStatusHUD::draw(DrawingContext& context)
if (m_bonus_sprites.find(m_player_status.m_item_pockets[i]) != m_bonus_sprites.end())
{
pos += 20;
Sprite* sprite = m_bonus_sprites[m_player_status.m_item_pockets.front()].get();
sprite->draw(context.color(), pos, LAYER_HUD);

Sprite* sprite = m_bonus_sprites[m_player_status.m_item_pockets[i]].get();
if (sprite)
sprite->draw(context.color(), pos, LAYER_HUD);
}
}
}
Expand Down

0 comments on commit cb5116a

Please sign in to comment.