fix ios line gradient crash and LineChart popup IOOBE#168
Open
NadeemIqbal wants to merge 2 commits into
Open
Conversation
CMP 1.11.0 changed the iOS Shader representation, so the legacy path `Paint().shader = LinearGradientShader(...)` plus drawIntoCanvas crashes at runtime with: ClassCastException: class androidx.compose.ui.graphics.Shader cannot be cast to class org.jetbrains.skia.Shader inside drawLineGradient. Switch to the public Compose API, drawPath(brush = Brush.verticalGradient(...)), which works on every target and avoids the raw shader downcast. The gradient was already strictly vertical (Offset(0f, 0f) to Offset(0f, height)), so the swap is 1:1. Function signature unchanged. Closes ehsannarmani#167
showPopup read linesPathData[dataIndex] and xPositions[startIndex]
without guarding against three cases:
1. A Line whose `values` list is empty produces empty xPositions; the
index access throws IndexOutOfBoundsException.
2. LaunchedEffect(data, ...) { linesPathData.clear() } empties the
state list whenever data updates, but a pointer event mid-update
still tries to read linesPathData[dataIndex], surfacing as
SnapshotStateList.get IOOBE on the gesture thread.
3. xPositions empty even when pathData is present.
Add three early-return guards before the index access. Each fails this
iteration only, so a malformed line does not poison a sibling line.
Closes ehsannarmani#146
Closes ehsannarmani#158
|
@ehsannarmani please review and merge, so the lib can be used with latest compose multiplatform versions |
Owner
|
Hi guys. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two independent fixes in
LineChart, kept as separate commits so they can be reviewed and reverted independently.1. iOS
ClassCastExceptionindrawLineGradienton CMP 1.11.0 (closes #167)Gradient.ktwas using the low-level Skia interop path:Paint().shader = LinearGradientShader(...)insidedrawIntoCanvas { it.drawPath(p, paint) }. In CMP <= 1.10 the iOS native bridge happened to unwrap this, but CMP 1.11.0 changed the internalShaderrepresentation, so the runtime downcast in the iOSpaint.shadersetter fails:Fix: use the public, multiplatform-safe
DrawScope.drawPath(path, brush)withBrush.verticalGradient. The original gradient was strictly vertical (Offset(0f, 0f)toOffset(0f, _size.height)), so the swap is 1:1 and removes thedrawIntoCanvasescape hatch entirely. Function signature is unchanged, both call sites inLineChart.ktkeep compiling.2.
LineChart.showPopupIOOBE on empty / stale line data (closes #146, closes #158)showPopupreadlinesPathData[dataIndex]andxPositions[startIndex]without guarding against three cases:Linewhosevalueslist is empty produces emptyxPositions; the index access throwsIndexOutOfBoundsException.LaunchedEffect(data, minValue, computedMaxValue) { linesPathData.clear() }empties the state list whenever data updates, but a pointer event mid-update still tries to readlinesPathData[dataIndex], surfacing asSnapshotStateList.getIOOBE on the gesture thread. This is exactly the stack in 🐛 LineChart crash in showPopup (IndexOutOfBoundsException) even when caller guards empty data #158.xPositionsempty even whenpathDatais present.Three early-return guards added before the index access. Each fails this iteration only, so a malformed line does not poison a sibling line.
Local build verification
No new warnings introduced.