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

[Pager] Page must be 0 when pageCount is 0 #1057

Closed
zoltish opened this issue Feb 28, 2022 · 4 comments
Closed

[Pager] Page must be 0 when pageCount is 0 #1057

zoltish opened this issue Feb 28, 2022 · 4 comments
Assignees

Comments

@zoltish
Copy link

zoltish commented Feb 28, 2022

Description
I received this crash log earlier today from someone rocking a Huawei Mate 20, running Android 10 (I dont think that matters?).

Fatal Exception: java.lang.IllegalArgumentException: page must be 0 when pageCount is 0
       at com.google.accompanist.pager.PagerState.requireCurrentPage(PagerState.kt:320)
       at com.google.accompanist.pager.PagerState.animateScrollToPage(PagerState.kt:195)
       at com.google.accompanist.pager.PagerState.animateScrollToPage$default(PagerState.java:191)
       at progression.design.structure.PagerKt$rememberPagerController$2.invokeSuspend(Pager.kt:108)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
       at androidx.compose.ui.platform.AndroidUiDispatcher.performTrampolineDispatch(AndroidUiDispatcher.android.kt:81)
       at androidx.compose.ui.platform.AndroidUiDispatcher.access$performTrampolineDispatch(AndroidUiDispatcher.android.kt:41)
       at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.run(AndroidUiDispatcher.android.kt:2)
       at android.os.Handler.handleCallback(Handler.java:900)
       at android.os.Handler.dispatchMessage(Handler.java:103)
       at android.os.Looper.loop(Looper.java:219)
       at android.app.ActivityThread.main(ActivityThread.java:8393)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)

Steps to reproduce
This happened out in the wild, but the related code that actually triggered the crash looks like this. Basically used to synchronize an external states current selection with the pager page.

    LaunchedEffect(currentPage) {
        if (state.targetPage != currentPage) {
            state.animateScrollToPage(
                page = currentPage
            )
        }
    }

Additional context
I cant tell which screen of my app lead to this crash, but every screen thats using a pager has at least 1 page at all times.

compose = '1.2.0-alpha04'
accompanist = '0.24.3-alpha'

@andkulikov
Copy link
Collaborator

Didn't you file #859 already for exactly this?

Realistically LaunchedEffect is executed before the pager is laid out at least once so this block could be called before we know the needed info for performing the scroll. So you can't call it too early

@zoltish
Copy link
Author

zoltish commented Feb 28, 2022

Oh snap. Sorry, I thought this was a new thing in the latest alpha release. I appreciate the explanation though, Ill work my way around it!

@zoltish zoltish closed this as completed Feb 28, 2022
@kasem-sm
Copy link

@zoltish any work around you found? Thanks!

@undermark5
Copy link

This was fixed by #1195, which is included as of v0.24.11-rc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants