Skip to content

array.sort behavior can differ between MSVC and GCC compilers #1347

@NotHyper-474

Description

@NotHyper-474
class Main {
	static function main() {
		var sortThing:Array<Null<Int>> = [0, 0, 1000, null, 800, 801, 802, 850, 850, 900, 1000, 1001, 10000, 10000, 10000];

		sortThing.sort((a, b) -> {
			if (a == null || b == null) return 0;
			return Reflect.compare(a, b);
		});

		trace(sortThing);
	}
}

I've noticed this behaved differently between the compilers.
On MSVC, sorting results in [0,0,1000,null,800,801,802,850,850,900,1000,1001,10000,10000,10000], but on GCC the same array instead becomes [0,0,850,1000,null,800,801,802,850,900,1000,1001,10000,10000,10000].

It's a minimal recreation of how objects in a game's scene are ordered, which also caused a bug.
While it uncovers a flaw with how the game's sorting objects, I considered that the discrepancy in how the sorting behaved between compilers could be a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions