hxcpp
hxcpp copied to clipboard
Array.sort with conflicting "comparator" outputs fails with access violation
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:
(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.