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

Don't crash when forest mapgen requests groundcover from a biome with no groundcover #72918

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions src/mapgen_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ void mapgen_forest( mapgendata &dat )
// In order to feather (blend) this overmap tile with adjacent ones, the general composition thereof must be known.
// This can be calculated once from dat.t_nesw, and stored here:
std::array<const forest_biome *, 8> adjacent_biomes;
for( int d = 0; d < 7; d++ ) {
for( int d = 0; d <= 7; d++ ) {
auto lookup = dat.region.forest_composition.biomes.find( dat.t_nesw[d]->get_type_id() );
if( lookup != dat.region.forest_composition.biomes.end() ) {
adjacent_biomes[d] = &( lookup->second );
Expand Down Expand Up @@ -1187,7 +1187,12 @@ void mapgen_forest( mapgendata &dat )
return *dat.region.default_groundcover.pick();
default:
if( adjacent_biomes[feather_selection] != nullptr ) {
return *adjacent_biomes[feather_selection]->groundcover.pick();
const ter_id *cover = adjacent_biomes[feather_selection]->groundcover.pick();
if( cover ) {
return *cover;
}
// Adjacent biome has no groundcover, use the region default.
return *dat.region.default_groundcover.pick();
} else {
return *dat.region.default_groundcover.pick();
}
Expand Down
24 changes: 17 additions & 7 deletions src/regional_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,29 @@ static void load_forest_mapgen_settings( const JsonObject &jo,
if( forest_biome_ter_keys.empty() ) {
forest_biome_jo.throw_error( "Biome is not associated with any terrains." );
}
std::string first_ter = forest_biome_ter_keys.get_string( 0 );
load_forest_biome( forest_biome_jo, forest_mapgen_settings.unfinalized_biomes[first_ter],
overlay );
for( size_t biome_ter_idx = 1; biome_ter_idx < forest_biome_ter_keys.size(); biome_ter_idx++ ) {
std::string default_ter_name = member.name();
auto default_ter_it = forest_mapgen_settings.unfinalized_biomes.find( default_ter_name );
if( default_ter_it == forest_mapgen_settings.unfinalized_biomes.end() ) {
if( overlay ) {
forest_biome_jo.throw_error( "Terrain " + default_ter_name +
" is not defined, cannot be used for forest biome." );
}
default_ter_it = forest_mapgen_settings.unfinalized_biomes.emplace( default_ter_name, forest_biome{} ).first;
}
forest_biome &default_ter = default_ter_it->second;
load_forest_biome( forest_biome_jo, default_ter, overlay );
for( size_t biome_ter_idx = 0; biome_ter_idx < forest_biome_ter_keys.size(); biome_ter_idx++ ) {
std::string biome_ter_name = forest_biome_ter_keys.get_string( biome_ter_idx );
if( biome_ter_name == default_ter_name ) {
continue;
}
forest_mapgen_settings.unfinalized_biomes.insert( std::pair<std::string, forest_biome>
( forest_biome_ter_keys.get_string( biome_ter_idx ),
forest_mapgen_settings.unfinalized_biomes[first_ter] ) );
( forest_biome_ter_keys.get_string( biome_ter_idx ), default_ter ) );
}
} else {
load_forest_biome( forest_biome_jo, forest_mapgen_settings.unfinalized_biomes[member.name()],
overlay );
}

}
}
}
Expand Down
Loading