hxcpp icon indicating copy to clipboard operation
hxcpp copied to clipboard

Array.sort with conflicting "comparator" outputs fails with access violation

Open YellowAfterlife opened this issue 4 years ago • 0 comments

class Main {
	static function main() {
		var shuffle = [1, 2, 3];
		var i = 0;
		Sys.print("Sorting...");
		shuffle.sort((a, b) -> ++i == 1 ? 1 : -1);
		Sys.println("OK!");
	}
}

Output:

Sorting...Press any key to continue . . .

Debugger reports somewhat random results but generally seems to come down to ObjectPtr::CastPtr inside the comparator call:

image (NB: screenshot from the original shuffle sample with a Math.random() call)

Evidently not something that you should be doing, but might be worth checking out or noting in documentation somewhere. I'm not seeing any restrictions of kind listed for std::stable_sort that the function uses.

YellowAfterlife avatar Jul 07 '21 10:07 YellowAfterlife