Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nullptr crash in player status hud due to wrong player item pocket access #3119

Conversation

Brockengespenst
Copy link
Contributor

@Brockengespenst Brockengespenst commented Nov 30, 2024

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.

…t access

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.
@Brockengespenst
Copy link
Contributor Author

Brockengespenst commented Nov 30, 2024

To be honest, I have not checked the whole item pocket logic, but I encountered a crash in local multiplayer mode. First player did not have any bonus while the second player gained a bonus and that caused the game to crash: While iterating the players, always the sprite for the first player was retrieved and drawn. As there is no sprite for BONUS_NONE, a nullptr was introduced to the map and the game crashed as it tried to draw a sprite from a nullptr.
I assume the check for if (m_bonus_sprites.find(m_player_status.m_item_pockets[i]) != m_bonus_sprites.end()) should check for the correct sprite, so I used this as well when retrieving the actual sprite. Additionally, I added a nullptr check, just to be sure.
@MatusGuy : Please check if there is anything wrong with my understanding.

@Brockengespenst Brockengespenst changed the title Fix nullptr crash in player status hud due to wrong player item pocke… Fix nullptr crash in player status hud due to wrong player item pocket access Nov 30, 2024
Co-authored-by: Vankata453 <78196474+Vankata453@users.noreply.github.com>
@MatusGuy
Copy link
Member

MatusGuy commented Dec 1, 2024

Oh my god wahahaha That slipped right through me indeed. Nice catch!

@Vankata453 Vankata453 merged commit cb5116a into SuperTux:master Dec 2, 2024
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants