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

Prevent crash from using invalidated explosion data #75711

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/explosion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,15 +911,29 @@ void resonance_cascade( const tripoint &p )

void process_explosions()
{
for( const queued_explosion &ex : _explosions ) {
if( _explosions.empty() ) {
return;
}

// Need to copy and clear this vector before processing the explosions.
// Part of processing in `_make_explosion` is handing out shrapnel damage,
// which might kill monsters. That might have all sorts of consequences,
// such as running eocs, loading new maps (via eoc) or other explosions
// being added. There is therefore a chance that we might recursively
// enter this function again during explosion processing, and we need to
// guard against references becoming invalidated either by items being
// added to the vector, or us clearing it here.
std::vector<queued_explosion> explosions_copy( _explosions );
_explosions.clear();

for( const queued_explosion &ex : explosions_copy ) {
const tripoint p = get_map().getlocal( ex.pos );
if( p.x < 0 || p.x >= MAPSIZE_X || p.y < 0 || p.y >= MAPSIZE_Y ) {
debugmsg( "Explosion origin (%d, %d, %d) is out-of-bounds", p.x, p.y, p.z );
continue;
}
_make_explosion( ex.source, p, ex.data );
}
_explosions.clear();
}

} // namespace explosion_handler
Expand Down
Loading