2307vivek / Seeker

A highly customizable seekbar/slider library for android with support for readahead indicator, segments and more. Made with Jetpack Compose ❤.
Apache License 2.0
371 stars 16 forks source link

[Bug] Comparing floats causing crashes #71

Closed abdallahmehiz closed 1 week ago

abdallahmehiz commented 1 week ago

I am using this library in my media player mpvKt and I've been seeing a lot crashes happening because of seeker (happening randomly too) Until i discovered it was happening due to this bug: https://github.com/2307vivek/Seeker/blob/e6e7ee26ca28484fbbbdcdf815687f13c090b818/seeker/src/main/java/dev/vivvvek/seeker/Seeker.kt#L131

Comparing floats is known to cause issues...

2307vivek commented 1 week ago

I will look into it. Are there any steps to reproduce the crash?

abdallahmehiz commented 1 week ago

I will look into it. Are there any steps to reproduce the crash?

Since it's an issue of comparing floats, it is reproducible only through chance. You can't make it crash consistently, but it will eventually crash. Here is an example: here it took me quite a few tries, but it eventually crashed be cause of this bug. Sometimes it takes less tries, sometimes more.

https://github.com/user-attachments/assets/1748fbaa-167e-4635-84a4-103e151037eb

abdallahmehiz commented 1 week ago

I've found out that it was actually not seeker causing the crashes, but mpv giving me an unordered chapters list. So I am closing this.

2307vivek commented 1 week ago

I suspected it. I wrote a script to compare a million floats within a range in kotlin, and it turns out to be all correct. Take a look here: https://pl.kotl.in/fpz8mXqTQ

I was digging into the kotlin code to check how float comparisons happen in kotlin, comparison symbols (<=) call the operator fun compareTo() which looks like takes care of the precision.