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 crash when removing grab effects from dead monsters #79009

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

junytse
Copy link
Contributor

@junytse junytse commented Jan 7, 2025

Summary

Bugfixes "Fix random crash when monster grabbing the player dies"

Purpose of change

Fix #76748

Describe the solution

https://github.com/CleverRaven/Cataclysm-DDA/blob/master/src/monster.cpp#L2958 looping through referenced objects while removing them, which cause dangling references.

The fix is to gather IDs of effect to be removed and remove by ID.

Describe alternatives you've considered

Testing

I meet this crash on my mac build with a high frequency when melee attack to kill a zombie strider.

Additional context

@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` Monsters Monsters both friendly and unfriendly. <Bugfix> This is a fix for a bug (or closes open issue) labels Jan 7, 2025
@@ -2954,17 +2954,24 @@ void monster::die( Creature *nkiller )
if( !grabbed ) {
you->add_msg_player_or_npc( m_good, _( "The last enemy holding you collapses!" ),
_( "The last enemy holding <npcname> collapses!" ) );
// A loop for safety
std::vector<efftype_id> effect_ids; // to avoid dangling references, prepare effect IDs before removing them
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JSON & C++ formatters] reported by reviewdog 🐶

Suggested change
std::vector<efftype_id> effect_ids; // to avoid dangling references, prepare effect IDs before removing them
std::vector<efftype_id>
effect_ids; // to avoid dangling references, prepare effect IDs before removing them

@github-actions github-actions bot added the json-styled JSON lint passed, label assigned by github actions label Jan 7, 2025
@junytse junytse marked this pull request as draft January 7, 2025 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions Monsters Monsters both friendly and unfriendly.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0.H RC: random crash
1 participant