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

Fixed crash when generating map #34148

Merged
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
14 changes: 11 additions & 3 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ void map::generate( const tripoint &p, const time_point &when )
// because other submaps won't be touched.
for( int gridx = 0; gridx < my_MAPSIZE; gridx++ ) {
for( int gridy = 0; gridy < my_MAPSIZE; gridy++ ) {
setsubmap( get_nonant( { gridx, gridy } ), new submap() );
const size_t grid_pos = get_nonant( { gridx, gridy, p.z } );
if( getsubmap( grid_pos ) ) {
debugmsg( "Submap already exists at (%d, %d, %d)", gridx, gridy, p.z );
continue;
}
setsubmap( grid_pos, new submap() );
// TODO: memory leak if the code below throws before the submaps get stored/deleted!
}
}
Expand Down Expand Up @@ -199,10 +204,13 @@ void map::generate( const tripoint &p, const time_point &when )
for( int j = 0; j < my_MAPSIZE; j++ ) {
dbg( D_INFO ) << "map::generate: submap (" << i << "," << j << ")";

const tripoint pos( i, j, p.z );
if( i <= 1 && j <= 1 ) {
saven( tripoint( i, j, p.z ) );
saven( pos );
} else {
delete get_submap_at_grid( { i, j, p.z } );
const size_t grid_pos = get_nonant( pos );
delete getsubmap( grid_pos );
setsubmap( grid_pos, nullptr );
}
}
}
Expand Down