mirror of https://github.com/OpenTTD/OpenTTD
Fix c2d4098afa: Crash when accessing unconfigurable badge feature. (#14403)
Some features support badges but do not have a way to configure them. Accessing these features could crash the game.pull/14404/head
parent
36d7e09369
commit
4fe6adb2dd
|
@ -118,15 +118,17 @@ void ResetBadgeClassConfiguration(GrfSpecFeature feature)
|
|||
*/
|
||||
std::pair<const BadgeClassConfigItem &, int> GetBadgeClassConfigItem(GrfSpecFeature feature, std::string_view label)
|
||||
{
|
||||
if (BadgeClassConfig::CONFIGURABLE_FEATURES.Test(feature)) {
|
||||
auto config = GetBadgeClassConfiguration(feature);
|
||||
auto found = std::ranges::find(config, label, &BadgeClassConfigItem::label);
|
||||
if (found == std::end(config)) {
|
||||
return {BadgeClassConfig::EMPTY_CONFIG_ITEM, 0};
|
||||
}
|
||||
|
||||
if (found != std::end(config)) {
|
||||
/* Sort order is simply the position in the configuration list. */
|
||||
return {*found, static_cast<int>(std::distance(std::begin(config), found))};
|
||||
}
|
||||
}
|
||||
|
||||
return {BadgeClassConfig::EMPTY_CONFIG_ITEM, 0};
|
||||
}
|
||||
|
||||
/**
|
||||
* Load badge column preferences.
|
||||
|
|
Loading…
Reference in New Issue