patrykandpatrick / vico

A light and extensible chart library for Android.
https://patrykandpatrick.com/vico/wiki
Apache License 2.0
2.15k stars 130 forks source link

ChartValuesProvider "IllegalStateException" #467

Closed Josuhu closed 8 months ago

Josuhu commented 11 months ago

How to reproduce

Unknown but error seems to ocure during onCreate

Observed behavior

FATAL Exception crash and app is in a crash loop, Image from the interface and exception is attached

Expected behavior

???

Vico version(s)

Latest stable version

Android version(s)

14

Additional information

Exception

Josuhu commented 11 months ago

I would try to solve it somehow but cannot find a away to reach this interface in the Vico API where it is executed.

patrickmichalik commented 11 months ago

Hello! Thanks for the report. You’ve mentioned that the reproduction steps are unknown. Does this occur only intermittently, as opposed to every time the Activity is created?

Josuhu commented 11 months ago

It works fine for the first time but starts crashing while app is closed and Activity is recreated or reopened with a new instance. So it seems it does not tolerate background restoration. It has happened after screen rotation as well and once it crashes it is in a crash loop with this exception.

patrickmichalik commented 11 months ago

I’ve tried to reproduce the issue by simulating process death and by repeatedly changing the screen orientation, but I’ve not been able to get a crash to occur. Would you be able to share an example?

matheusPereiraG commented 11 months ago

Im also getting this crash and i cannot deterministically reproduce it. The only thing i know of this is that it can occur randomly and mostly when re-populating data onto the graph (Im also using the latest stable version)

patrickmichalik commented 11 months ago

Thanks for letting us know, @matheusPereiraG. Are you using Vico with the view system?

matheusPereiraG commented 11 months ago

Thanks for letting us know, @matheusPereiraG. Are you using Vico with the view system?

No, im using jetpack compose.

patrickmichalik commented 11 months ago

Thanks, @matheusPereiraG! Unfortunately, we still haven’t been able to reproduce this, whether in Jetpack Compose or in the view system. You’ve mentioned that the crash can occur during data updates. Just to confirm, do these updates coincide with anything notable, such as activity recreation? More or less how often does the crash occur?

aleksandra-krzemien commented 10 months ago

I see the same exception, and I prepared a small demo repo (this specific branch). In my case, I have a ComposeView and HorizontalPager where each page contains a graph. I want to animate graph values with some delay, so I use ChartEntryModelProducer and setEntriesSuspending with delay. I'm not sure if this is the right way to update entries with delay, so if not, please let me know. However, with current approach the exception occurs pretty often.

Steps to reproduce:

  1. Tap button to second fragment
  2. Swipe between pages left and right
  3. At some point the exception is thrown.

It's not thrown at the same moment each time, but eventually it occurred for me every time I tested it. The issue appears also when I comment out updating value in the loop, but I think it happens less often then.

ps. This is not the topic of this issue, but in the case above I also noticed that the initial value for different pages is not always animated (when I comment out updating values in a loop). I would really appreciate if you let me know if this is an issue with my setup or is it a bug on your side. If this is not the place for this question, I can create a separate issue.

aleksandra-krzemien commented 10 months ago

I found a workaround for the issue (both issues actually) I described above. It seems that the Pager is a part of the issue. If I set entries only when pageIndex == pagerState?.currentPage the exception does not occur.

The animation also works just fine, but it makes perfect sense, as Pager loads more items than are actually visible and I want to animate graph only when particular page is shown.

patrickmichalik commented 10 months ago

Thanks for the example, @aleksandra-krzemien! We’ve identified the issue. There’s a race condition, so changing when an affected chart’s data is updated (relative to when the chart is created) may prevent the crash from occurring, but generally, this is a bug. We have a fix and will release an update shortly.

Regarding initial animations, that’s exactly right—HorizontalPager preloads its pages, and a chart’s initial animation is started when the chart enters composition.

patrickmichalik commented 10 months ago

Vico 2.0.0 Alpha 5 addresses this. We also plan on releasing a Vico 1 update with a fix.

patrickmichalik commented 9 months ago

The aforementioned Vico 1 update, Vico 1.14.0 Alpha 2, is now available.

patrickmichalik commented 8 months ago

Vico 1.14.0 is rolling out. Cheers!