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,14 +118,16 @@ void ResetBadgeClassConfiguration(GrfSpecFeature feature)
|
||||||
*/
|
*/
|
||||||
std::pair<const BadgeClassConfigItem &, int> GetBadgeClassConfigItem(GrfSpecFeature feature, std::string_view label)
|
std::pair<const BadgeClassConfigItem &, int> GetBadgeClassConfigItem(GrfSpecFeature feature, std::string_view label)
|
||||||
{
|
{
|
||||||
|
if (BadgeClassConfig::CONFIGURABLE_FEATURES.Test(feature)) {
|
||||||
auto config = GetBadgeClassConfiguration(feature);
|
auto config = GetBadgeClassConfiguration(feature);
|
||||||
auto found = std::ranges::find(config, label, &BadgeClassConfigItem::label);
|
auto found = std::ranges::find(config, label, &BadgeClassConfigItem::label);
|
||||||
if (found == std::end(config)) {
|
if (found != std::end(config)) {
|
||||||
return {BadgeClassConfig::EMPTY_CONFIG_ITEM, 0};
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Sort order is simply the position in the configuration list. */
|
/* Sort order is simply the position in the configuration list. */
|
||||||
return {*found, static_cast<int>(std::distance(std::begin(config), found))};
|
return {*found, static_cast<int>(std::distance(std::begin(config), found))};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {BadgeClassConfig::EMPTY_CONFIG_ITEM, 0};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue