Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Use of unstable sort when distributing cargo production can caus… #9460

Merged
merged 1 commit into from Aug 1, 2021

Conversation

ldpl
Copy link
Contributor

@ldpl ldpl commented Jul 31, 2021

Motivation / Problem

Unstable std::sort is used to sort stations by rating so the order of stations with the same rating is not guaranteed and can differ between platforms so different stations receive leftover cargo causing desyncs. At least one platform is known to be affected so far (android): pelya/openttd-android#12

Description

Replacing std::sort with std::stable_sort should fix the issue as used_stations are guaranteed to b initially ordered by id due to std::set iteration.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.~
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@glx22 glx22 added the backport requested This PR should be backport to current release (RC / stable) label Jul 31, 2021
JGRennison pushed a commit to JGRennison/OpenTTD-patches that referenced this pull request Jul 31, 2021
…e desyncs

(cherry picked from commit 4ed694fe98b146d984826d06b96e0c11045239bc)

See: OpenTTD/OpenTTD#9460
@rubidium42 rubidium42 merged commit c1d7939 into OpenTTD:master Aug 1, 2021
@ldpl ldpl deleted the station-cargo-sort-desync branch August 2, 2021 13:22
@TrueBrain TrueBrain removed the backport requested This PR should be backport to current release (RC / stable) label Oct 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants