Skip to content

Commit

Permalink
Merge pull request #42545 from andrei8l/fix-loading-crash
Browse files Browse the repository at this point in the history
map: only actualize after loading all submaps
  • Loading branch information
ZhilkinSerg authored Aug 18, 2020
2 parents c73a6f0 + 5643f0a commit 0f7a804
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
18 changes: 15 additions & 3 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6676,7 +6676,16 @@ void map::load( const tripoint_abs_sm &w, const bool update_vehicle )
set_abs_sub( w.raw() );
for( int gridx = 0; gridx < my_MAPSIZE; gridx++ ) {
for( int gridy = 0; gridy < my_MAPSIZE; gridy++ ) {
loadn( point( gridx, gridy ), update_vehicle );
loadn( point( gridx, gridy ), update_vehicle, false );
}
}
// actualize after loading all submaps to prevent errors
// with entities at the edges
for( int gridx = 0; gridx < my_MAPSIZE; gridx++ ) {
for( int gridy = 0; gridy < my_MAPSIZE; gridy++ ) {
for( int gridz = -OVERMAP_DEPTH; gridz <= OVERMAP_HEIGHT; gridz++ ) {
actualize( tripoint( point( gridx, gridy ), gridz ) );
}
}
}
}
Expand Down Expand Up @@ -6966,7 +6975,7 @@ static void generate_uniform( const tripoint &p, const ter_id &terrain_type )
}
}

void map::loadn( const tripoint &grid, const bool update_vehicles )
void map::loadn( const tripoint &grid, const bool update_vehicles, bool _actualize )
{
// Cache empty overmap types
static const oter_id rock( "empty_rock" );
Expand Down Expand Up @@ -7061,7 +7070,10 @@ void map::loadn( const tripoint &grid, const bool update_vehicles )
}
}

actualize( grid );
// don't actualize before all maps are loaded
if( _actualize ) {
actualize( grid );
}

abs_sub.z = old_abs_z;
}
Expand Down
8 changes: 4 additions & 4 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -1501,11 +1501,11 @@ class map

protected:
void saven( const tripoint &grid );
void loadn( const tripoint &grid, bool update_vehicles );
void loadn( const point &grid, bool update_vehicles ) {
void loadn( const tripoint &grid, bool update_vehicles, bool _actualize = true );
void loadn( const point &grid, bool update_vehicles, bool _actualize = true ) {
if( zlevels ) {
for( int gridz = -OVERMAP_DEPTH; gridz <= OVERMAP_HEIGHT; gridz++ ) {
loadn( tripoint( grid, gridz ), update_vehicles );
loadn( tripoint( grid, gridz ), update_vehicles, _actualize );
}

// Note: we want it in a separate loop! It is a post-load cleanup
Expand All @@ -1514,7 +1514,7 @@ class map
add_roofs( tripoint( grid, gridz ) );
}
} else {
loadn( tripoint( grid, abs_sub.z ), update_vehicles );
loadn( tripoint( grid, abs_sub.z ), update_vehicles, _actualize );
}
}
/**
Expand Down

0 comments on commit 0f7a804

Please sign in to comment.