summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJonathan G Rennison <j.g.rennison@gmail.com>2020-01-07 00:34:17 +0000
committerNiels Martin Hansen <nielsm@indvikleren.dk>2020-01-07 09:03:36 +0100
commit4cc1420beb0470ba076c5f30dbd57b05489b0b1b (patch)
tree302443695f8952151438ff9bbd2792cf50eb6a3b /src
parenta0066ebca103fc71799a6009c40104a4ff4868fa (diff)
downloadopenttd-4cc1420beb0470ba076c5f30dbd57b05489b0b1b.tar.xz
Fix: Non-deterministic name sorting in industry directory window
In the case where multiple industries have the same name, sorting in the industry directory window is non-deterministic. This results in the order changing on each re-sort, and is noticeable when the industries have different production or transported values.
Diffstat (limited to 'src')
-rw-r--r--src/industry_gui.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index 6be98e280..7a45c1192 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -1410,7 +1410,9 @@ protected:
GetString(buf_cache, STR_INDUSTRY_NAME, lastof(buf_cache));
}
- return strnatcmp(buf, buf_cache) < 0; // Sort by name (natural sorting).
+ int r = strnatcmp(buf, buf_cache); // Sort by name (natural sorting).
+ if (r == 0) return a->index < b->index;
+ return r < 0;
}
/** Sort industries by type and name */