Skip to content

Commit a6d2c0f

Browse files
authored
Merge pull request #5198 from sorinmiroiu97/sorin/crash-fix/5197
Charts/issues/5197 - fixed host app crash by adding a check before ca…
2 parents 019d979 + 301a2bd commit a6d2c0f

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

Source/Charts/Renderers/BarLineScatterCandleBubbleRenderer.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ open class BarLineScatterCandleBubbleRenderer: NSObject, DataRenderer
6666
open func isDrawingValuesAllowed(dataProvider: ChartDataProvider?) -> Bool
6767
{
6868
guard let data = dataProvider?.data else { return false }
69-
return data.entryCount < Int(CGFloat(dataProvider?.maxVisibleCount ?? 0) * viewPortHandler.scaleX)
69+
let count = CGFloat(dataProvider?.maxVisibleCount ?? 0) * viewPortHandler.scaleX
70+
guard count < CGFloat.infinity, !count.isNaN else { return false }
71+
return data.entryCount < Int(count)
7072
}
7173

7274
/// Class representing the bounds of the current viewport in terms of indices in the values array of a DataSet.

Source/Charts/Renderers/CombinedChartRenderer.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ open class CombinedChartRenderer: NSObject, DataRenderer
162162
open func isDrawingValuesAllowed(dataProvider: ChartDataProvider?) -> Bool
163163
{
164164
guard let data = dataProvider?.data else { return false }
165-
return data.entryCount < Int(CGFloat(dataProvider?.maxVisibleCount ?? 0) * viewPortHandler.scaleX)
165+
let count = CGFloat(dataProvider?.maxVisibleCount ?? 0) * viewPortHandler.scaleX
166+
guard count < CGFloat.infinity, !count.isNaN else { return false }
167+
return data.entryCount < Int(count)
166168
}
167169

168170
/// All sub-renderers.

Source/Charts/Renderers/HorizontalBarChartRenderer.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,9 +614,10 @@ open class HorizontalBarChartRenderer: BarChartRenderer
614614

615615
open override func isDrawingValuesAllowed(dataProvider: ChartDataProvider?) -> Bool
616616
{
617-
guard let data = dataProvider?.data
618-
else { return false }
619-
return data.entryCount < Int(CGFloat(dataProvider?.maxVisibleCount ?? 0) * self.viewPortHandler.scaleY)
617+
guard let data = dataProvider?.data else { return false }
618+
let count = CGFloat(dataProvider?.maxVisibleCount ?? 0) * viewPortHandler.scaleY
619+
guard count < CGFloat.infinity, !count.isNaN else { return false }
620+
return data.entryCount < Int(count)
620621
}
621622

622623
/// Sets the drawing position of the highlight object based on the riven bar-rect.

Source/Charts/Renderers/PieChartRenderer.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,9 @@ open class PieChartRenderer: NSObject, DataRenderer
578578
open func isDrawingValuesAllowed(dataProvider: ChartDataProvider?) -> Bool
579579
{
580580
guard let data = dataProvider?.data else { return false }
581-
return data.entryCount < Int(CGFloat(dataProvider?.maxVisibleCount ?? 0) * viewPortHandler.scaleX)
581+
let count = CGFloat(dataProvider?.maxVisibleCount ?? 0) * viewPortHandler.scaleX
582+
guard count < CGFloat.infinity, !count.isNaN else { return false }
583+
return data.entryCount < Int(count)
582584
}
583585

584586
/// draws the hole in the center of the chart and the transparent circle / hole

0 commit comments

Comments
 (0)