From 4cc1420beb0470ba076c5f30dbd57b05489b0b1b Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 7 Jan 2020 00:34:17 +0000 Subject: [PATCH] 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. --- src/industry_gui.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 6be98e2804..7a45c11921 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 */