Fix potential use of old names in group and engine name sorters
This could result in violation of strict weak ordering
This commit is contained in:
@@ -106,20 +106,22 @@ static const NWidgetPart _nested_group_widgets[] = {
|
||||
EndContainer(),
|
||||
};
|
||||
|
||||
/* cached values for GroupNameSorter to spare many GetString() calls */
|
||||
static const Group *_last_group[2] = { nullptr, nullptr };
|
||||
|
||||
/** Sort the groups by their name */
|
||||
bool GroupNameSorter(const Group * const &a, const Group * const &b)
|
||||
{
|
||||
static const Group *last_group[2] = { nullptr, nullptr };
|
||||
static char last_name[2][64] = { "", "" };
|
||||
|
||||
if (a != last_group[0]) {
|
||||
last_group[0] = a;
|
||||
if (a != _last_group[0]) {
|
||||
_last_group[0] = a;
|
||||
SetDParam(0, a->index);
|
||||
GetString(last_name[0], STR_GROUP_NAME, lastof(last_name[0]));
|
||||
}
|
||||
|
||||
if (b != last_group[1]) {
|
||||
last_group[1] = b;
|
||||
if (b != _last_group[1]) {
|
||||
_last_group[1] = b;
|
||||
SetDParam(0, b->index);
|
||||
GetString(last_name[1], STR_GROUP_NAME, lastof(last_name[1]));
|
||||
}
|
||||
@@ -207,6 +209,10 @@ private:
|
||||
this->SetWidgetDisabledState(WID_GL_COLLAPSE_ALL_GROUPS, !enable_collapse_all);
|
||||
|
||||
list.ForceResort();
|
||||
|
||||
/* invalidate cached values for name sorter - group names could change */
|
||||
_last_group[0] = _last_group[1] = nullptr;
|
||||
|
||||
list.Sort(&GroupNameSorter);
|
||||
|
||||
AddChildren(&list, INVALID_GROUP, 0);
|
||||
|
Reference in New Issue
Block a user