From 68a1271ab000458594016aaec421ef3169f65d5b Mon Sep 17 00:00:00 2001 From: JugadorXEI Date: Tue, 22 Apr 2025 19:23:50 +0000 Subject: [PATCH] Fix loop desyncs (by making loop end point sorting consistent) --- src/p_setup.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 5bc77bc9f..06642755a 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -784,9 +784,13 @@ static int cmp_loopends(const void *a, const void *b) *mt2 = *(const mapthing_t*const*)b; // weighted sorting; tag takes precedence over type - return - intsign(mt1->tid - mt2->tid) * 2 + + const int maincomp = intsign(mt1->tid - mt2->tid) * 2 + intsign(mt1->thing_args[0] - mt2->thing_args[0]); + + // JugadorXEI (04/20/25): If a qsort comparison ends up with an equal result, + // it results in UNSPECIFIED BEHAVIOR, so assuming the previous two comparisons + // are equal, let's make it consistent with Linux behaviour (ascending order). + return maincomp != 0 ? maincomp : intsign((mt1 - mapthings) - (mt2 - mapthings)); } static void P_SpawnMapThings(boolean spawnemblems)