HaxeFoundation / HaxeFoundation/hxcpp
Array.sort with conflicting "comparator" outputs fails with access violation
- Dominant language
- C++
- Stars
- 330
- Forks
- 227
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 18
Description
```haxe
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.