HaxeFoundation / HaxeFoundation/hxcpp

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

Open
#961 0 comments 0 reactions 0 assignees View on GitHub
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:

![image](https://user-images.githubusercontent.com/731492/124746123-30c80480-df29-11eb-90ac-72e48ccfb3da.png)
(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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.