Giter VIP home page Giter VIP logo

Comments (8)

L-Andrade avatar L-Andrade commented on September 27, 2024 1

Hey! Thanks for the reply

Hello. I did some stress testing and I haven't experienced this crash.

Could it be because the CartesianChartModelProducer is recreated when the chart is visible again?

This shouldn't be the reason. Have you tried putting CartesianChartModelProducer in the viewmodel, as suggested here? The examples use LaunchedEffect for simplicity, but especially when the chart leaves and enters the composition, it's more optimal to store the producer in the viewmodel.

Yes, looking further into it, it seems like putting it in the ViewModel would most likely solve it. We were just trying to avoid it since we wanted the chart implementation to be part of a UI-only module, and this way we'll also have to put it a Vico dependency in the module that the ViewModel is in. Or we will have to create a wrapper around it. Reason we wanted to keep it out of the ViewModel is in case we'd want to change the implementation or library, we would have fewer places to change and it would be more contained.

Do you folks have any idea of how we can try to replicate this issue?

It's hard to tell without specific information. Is there anything common between the incidents? Like low-spec devices?

So far only had issues with Android 12, 13, and 14. Devices are not low-spec, they're decent (most common so far is Galaxy A53 5G).

I tried to understand the internal Vico code and had an idea, but might be totally wrong. Maybe still worth checking on your side just in case though. Click here to check the details

I was taking a look at the logic in CartesianChartModelProducer, and I think there are potential race conditions. With debugging breakpoints (non-suspend, log only) we can see that registerForUpdates (suspend function) and unregisterFromUpdates can be called before, during, or after tryUpdate. This can mean that a transaction might be running when a receiver is registered/unregistered, which could cause the ConcurrentModificationException. registerForUpdates is also called inside a scope.launch - which is scheduled to be immediately run, but might there might be a delay (albeit small of course) if

To solve it, registering or unregistering a receiver would need to either:

  1. Check and wait for the Mutex lock before setting/removing
  2. Cancel any ongoing transaction before setting/removing

Otherwise there might be an unfortunate timing.

With that said, I still can't replicate the issue, so I'm probably still missing something! I think I will try to move it to the ViewModel and see if it's fixed, but I believe the race condition will still be possible, just less probable (almost impossible, I guess) since the transaction will most likely be done before the chart is composed, and as such the receiver will always be registered after the transaction is complete (and fewer transactions will also be done, since it will not be done every time the chart is composed), and there's a smaller chance of a transaction being ran when unregistering since there will be fewer transactions too.

from vico.

Gowsky avatar Gowsky commented on September 27, 2024

Hello. I did some stress testing and I haven't experienced this crash.

Could it be because the CartesianChartModelProducer is recreated when the chart is visible again?

This shouldn't be the reason. Have you tried putting CartesianChartModelProducer in the viewmodel, as suggested here? The examples use LaunchedEffect for simplicity, but especially when the chart leaves and enters the composition, it's more optimal to store the producer in the viewmodel.

Do you folks have any idea of how we can try to replicate this issue?

It's hard to tell without specific information. Is there anything common between the incidents? Like low-spec devices?

Let me know if you see any issue in our implementation too, please!

I can't see any issues that could cause this.

from vico.

ibcurly avatar ibcurly commented on September 27, 2024

I also got this crash, spent a few hours looking for the culprit no luck yet

in the below code, yRanges[axisPosition] returns null because yRanges is empty and yRanges.getValue(null) throws the NoSuchElementException with the message "Key null is missing in the map."

in MutableChartValues.kt

public fun MutableChartValues.toImmutable(): ChartValues =
    object : ChartValues {
        private val yRanges = [email protected]
        override val minX: Float = [email protected]
        override val maxX: Float = [email protected]
        override val xStep: Float = [email protected]
        override val model: CartesianChartModel = [email protected]()
        override fun getYRange(axisPosition: AxisPosition.Vertical?): ChartValues.YRange =
            yRanges[axisPosition] ?: yRanges.getValue(null)
    }

UPDATE:

I was using the chart host that takes in a CartesianChartModel instead of the CartesianChartModelProducer. After changing it to match OP's implementation with the model producer and the LaunchedEffect, I no longer see the issue, so I'm not sure why OP has the issue. 🤷

from vico.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.