Closed volzhs closed 6 years ago
I bet the problem comes for the fact that the algorithm was designed with constant compare functions in mind, not some that return a random number...
I believe it uses the Heapsort algorithm and it indeed assumes that the comparison function is consistent.
Sorting is not a good method to shuffle an array anyway. There are solutions that runs in O(n).
I changed way to shuffle array to work correctly. It's up to godot dev team to close this issue if I shouldn't do this way and it's not a bug.
@volzhs You can change the issue to a request to warn the user when the function used isn't consistent (only in debug mode).
I'm not sure how the comparison function can be tested for consistency (or even if it should be). But I agree that crashing is never good.
not always, but very often crashed on Windows 7.
I ran this code 20 times on Windows 7. 8 times good, and 12 times crashed.
1 of 30 crashed on Ubuntu 14.04.
and one more weird thing is sometimes element is missing.
this is on Windows 7.
this is on Ubuntu 14.04