Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scroll NaN rounding bug, desktop version #304

Closed
LAP2 opened this issue Jan 22, 2021 · 3 comments
Closed

Scroll NaN rounding bug, desktop version #304

LAP2 opened this issue Jan 22, 2021 · 3 comments
Assignees
Labels
bug Something isn't working scroll
Milestone

Comments

@LAP2
Copy link
Contributor

LAP2 commented Jan 22, 2021

Hi folks.

There is a divide by zero bug in androidx.compose.foundation.SliderAdapter class
During scrollScale calculation it is possible that contentSize would be equal to containerSize, as result we get NaN in scrollScale and "Cannot round NaN value." exception in the end.

Steps to reproduce:

  1. Create window with vertical scroll, but larger that scrollable content, vertical scroll should not be visible.
  2. Click in place where vertical scroll should be.

Scroll scale calculation code fragment:
private val scrollScale get() = (containerSize - size) / (contentSize - containerSize)

You can find exception text in attachment.
NaN_exception.txt

@igordmn igordmn self-assigned this Jan 22, 2021
@olonho olonho added the scroll label Jan 22, 2021
@igordmn igordmn added the bug Something isn't working label Jan 22, 2021
@olonho olonho added this to the M3 milestone Feb 2, 2021
@dzirbel
Copy link

dzirbel commented Apr 18, 2021

I'm seeing the same thing, sadly it freezes the entire UI with no explanation to the user. My strack trace is a little different, posting it here in case it's helpful:

Stack trace
Exception in thread "AWT-EventQueue-0 @coroutine#63641" java.lang.IllegalArgumentException: Cannot round NaN value.
	at kotlin.math.MathKt__MathJVMKt.roundToInt(MathJVM.kt:1132)
	at androidx.compose.foundation.ScrollableScrollbarAdapter.scrollTo(Scrollbar.desktop.kt:369)
	at androidx.compose.foundation.Scrollbar_desktopKt$scrollOnPressOutsideSlider$1$1.invokeSuspend(Scrollbar.desktop.kt:283)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at androidx.compose.ui.platform.FlushCoroutineDispatcher.flush(FlushCoroutineDispatcher.desktop.kt:56)
	at androidx.compose.ui.platform.FlushCoroutineDispatcher$dispatch$1$1.invokeSuspend(FlushCoroutineDispatcher.desktop.kt:40)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:316)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

Compose 0.4.0-build182, JDK 16, Ubuntu 20.10.

@J-MR-T
Copy link

J-MR-T commented May 1, 2021

I am also experiencing this issue. From what I can see, this is triggered by the position of the sliderAdapter being NaN in Scrollbar.desktop.kt at line 296 (compose 0.3.2), where sliderAdapter.position is used to calculate oldSign, which results in oldSign being NaN, thus NaN being used as the scrollOffset parameter for scrollbarAdapter.scrollTo(). There the roundToInt() call on the scrollOffset triggers the actual Exception. The quickest fix for this would probably be a NaN check on sliderAdapter.position which stops the scrollTo() method even being called, for example by breaking from the while loop, just as the if in line 303 of the same file does.

@igordmn
Copy link
Collaborator

igordmn commented May 12, 2021

Should be fixed in 0.4.0-build190

@igordmn igordmn closed this as completed May 12, 2021
MatkovIvan pushed a commit to MatkovIvan/compose-multiplatform that referenced this issue May 10, 2023
…when it waits for release event (JetBrains#304)

Co-authored-by: Oleksandr Karpovich <oleksandr.karpovich@jetbrains.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working scroll
Projects
None yet
Development

No branches or pull requests

5 participants