AndreiMisiukevich / CardView

CardsView | CarouselView | CoverflowView | CubeView for Xamarin.Forms
MIT License
710 stars 114 forks source link

UWP crash when moving between monitors with different DPI #420

Closed daltzctr closed 2 years ago

daltzctr commented 2 years ago

I don't have the stacktrace (hopefully I can grab it), but occassionally I'll get an exception regarding "Invalid Bounds" pointing at the CarouselView as the offender when moving the UWP application between different monitors having different DPIs.

AndreiMisiukevich commented 2 years ago

@daltzctr please feel free to debug that and submit a PR with fix

daltzctr commented 2 years ago

Okay, I'm able to consistently reproduce the crash and have an exception. I'm going to pull the project source into my project to debug further. image

AndreiMisiukevich commented 2 years ago

Perhaps this line https://github.com/AndreiMisiukevich/CardView/blob/master/PanCardView/CardsView.cs#L1607 should be wrapped by UI thread invocation for UWP

Daltz333 commented 2 years ago

I'll give that a test when I'm in the office tomorrow. Thanks again.

daltzctr commented 2 years ago

I've successfully narrowed down the issue to https://github.com/AndreiMisiukevich/CardView/blob/9865b194534e0a6f8530d8ac8f49037a482b5294/PanCardView/Processors/CarouselProcessor.cs#L207-L212

It seems like these functions are returning NaN and BatchCommit was barfing on an input of NaN for the various UI elements. I fixed this by rewriting CalculateFactoredProperty like the following


protected virtual double CalculateFactoredProperty(double value, double factor, CardsView cardsView, double defaultFactorValue = 1)
{ 
    var val = Abs(value) * (factor - defaultFactorValue) / cardsView.GetSize() + defaultFactorValue;

    if (!double.IsNaN(val)) {
        return val;
    } else {
        return defaultFactorValue;
    }
}