Gaming32 / ArrayV

New home of https://github.com/MusicTheorist/ArrayVisualizer
MIT License
303 stars 47 forks source link

Exception in thread "ComparisonSorting", index 32768 out of bounds for length 32768 #110

Open rylid-umil opened 1 month ago

rylid-umil commented 1 month ago

When a sort ended on length 32768 length, the visual freezes, highlights and sound are frozen, but not cause of a freeze bug, it was beacuse it seemed when it tried to end the sort, the clear all marks bugged out. image I dont know why, but i didnt edit the highlight code, so it must be the same from my to your fork. It happens when i disable "End sweep anim", and when i am using a custom sort "Adaptive Sort" i made but not when i am using any other sorts. I do not get why it does not work, as if it was a mark index that was out of bounds (example Highlights.markArray(1, 32768) at 32768 length) it would've thrown an error at me, but it didn't. Yes, i tested importing my sort into your fork (with the added importation of MathExtra from the code) but it did not work.

EmeraldBlock commented 1 month ago

Please provide a clear step-by-step procedure of how to reproduce this, along with all files and code modifications you made. Otherwise, (1) we have literally no way to debug this, and (2) it could be that the issue is with the code you made.

rylid-umil commented 1 month ago

Step by step instruction to reproduce:

  1. Import AdaptiveSort.java (latest version) to the ArrayV.
  2. I made no changes to Highlights.java so i don't get how it will make an exception. (It also freezes when it reaches the end at length 4096 and probably other lengths but without the error (Unrelated but Flammer Sort also gives an error-thrown out of bounds for length 32768)
  3. Make sure to import MathExtra.java since Adaptive sort uses some of those functions.
  4. run the sort (recommended run on Randomly / Naiver randomly (slight shuffle but swaps N times) on 32768 length) 5.when sort ends, it should freeze and the sounds should freeze as well and you probably be thrown an out of bounds exception not as an error but through the console. I tried with end sweep anim disabled and enabled Video of the issue:

https://github.com/user-attachments/assets/b27a75cb-e7b2-4ee2-a471-49a4338922ef

It seems to happen in the clearAllMarks function. SO maybe a highlight was placed at 32768? Or maybe the length 32768 is so long it bugs out sorts (like FlammerSort), but if a highlight was placed at 32768 (out of bounds) the Highlights.markArray(1, 32768); would've thrown an out of bounds error at me but it didn't. it was the clear all marks function.

EmeraldBlock commented 1 month ago

I'm confused, isn't there clearly an out-of-bounds error displayed in an error popup before you check the console? Anyway, the error occurs while the sort is still running, so it seems like it's an issue with your own sort.

rylid-umil commented 1 month ago

What could the issue be then? Also, before i did the recording, there was no error message that popped up. If it was a Highlights.markArray(1, 32768);, it would have shown an out of bounds error originating from a markArray, but here it shows from a clearAllMarks.

rylid-umil commented 1 month ago

I've traced down the reason, described in this PR #101 image So it is a problem with my sort, but it doesn't throw an exception early due to this. This probably also is the case with FlammerSort, but it doesn't seem to happen with lengths < 32768 (it works just fine no errors in console or in program)