Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad reference when using cubic bezier for Line chart #47

Open
Archez opened this issue Dec 13, 2021 · 2 comments
Open

Bad reference when using cubic bezier for Line chart #47

Archez opened this issue Dec 13, 2021 · 2 comments

Comments

@Archez
Copy link

Archez commented Dec 13, 2021

Summary

There seems to be a crash with the cubic bezier generate function for the line chart renderer when the data set changes and the graph is redrawn.

We have a line chart that displays a set of data for a time frame (x-axis is time). The chart refreshes once a minute and slowly shifts the graph away. Our API also only returns data for the valid time frame, e.g. if on the first load we may have 12 data points, and on the next call the first (oldest) data point will no longer get sent down and the graph will no longer display it.

I have not been able to figure out the exact steps to make it happen, but the crash generally occurs when the app is open and the device is locked for a few minutes, after unlocking the device the app crashes.

JS: ERROR: UnhandledError Error: Calling js method onDraw failed
JS: TypeError: Cannot read property 'next' of undefined generateCubicPath(file: node_modules/@nativescript-community/ui-chart/renderer/LineChartRenderer.js:243:0)
JS:     at draw(file: node_modules/@nativescript-community/ui-chart/renderer/LineChartRenderer.js:414:0)
JS:     at drawDataSet(file: node_modules/@nativescript-community/ui-chart/renderer/LineChartRenderer.js:146:0)
JS:     at drawData(file: node_modules/@nativescript-community/ui-chart/renderer/LineChartRenderer.js:129:0)
JS:     at onDraw(file: node_modules/@nativescript-community/ui-chart/charts/BarLineChartBase.js:120:0)
JS:     at onDraw(file: node_modules/@nativescript-community/ui-canvas/canvas.android.js:538:0)

Expected Behavior

No bad reference when computing the cubic bezier path.

Possible Solution

Add an extra check for the first pass of the cubic path generate logic.

Device (please complete the following information):

  • Device: Google Pixel 4
  • Android Version: 10.0
  • Library Version: 1.2.14

Additional Context

The bad reference line in question is

float32arr[index++] = prevControlPoints.next.x;

const firstIndex = Math.max(0, this.mXBounds.min);
// let firstIndex = this.mXBounds.min + 1;
const lastIndex = this.mXBounds.min + this.mXBounds.range;
const float32arr = this.mLineBuffer;
let index = 0;
let nextIndex = -1;
let next: XYPoint;
let controlPoints;
let point: XYPoint;
let prev: XYPoint;
let prevControlPoints;
for (let j = firstIndex; j <= lastIndex; j++) {
point = getXYValue(dataSet, j);
if (!point) {
if (j === 0) {
return [];
}
continue;
}
if (!prev) {
prev = point;
}
nextIndex = j + 1 < dataSet.getEntryCount() ? j + 1 : j;
next = getXYValue(dataSet, nextIndex);
if (!next) {
continue;
}
controlPoints = splineCurve(prev, point, next, intensity);
if (j === 0) {
float32arr[index++] = point.x;
float32arr[index++] = point.y * phaseY;
} else {
float32arr[index++] = prevControlPoints.next.x;
float32arr[index++] = prevControlPoints.next.y * phaseY;
float32arr[index++] = controlPoints.previous.x;
float32arr[index++] = controlPoints.previous.y * phaseY;
float32arr[index++] = point.x;
float32arr[index++] = point.y * phaseY;
}
prevControlPoints = controlPoints;
prev = point;
}

and my guess is this is happening because on the first run of this loop, j which is firstIndex is greater than 0, so the code tries to reference prevControlPoints which has not be created yet.


ADD A REWARD using Speed to SOLVE this issue QUICKLY and SUPPORT this project.

@Archez Archez changed the title Crash when using cubic bezier for Line chart Bad reference when using cubic bezier for Line chart Dec 13, 2021
@DiegoMacBD
Copy link
Contributor

@farfromrefug sorry to tag you just wanted to know if you had a chance to look into this.

@farfromrefug
Copy link
Member

@DiegoMacBD there is something wrong with the chart data passed. I can fix it but i need to have sample ChartData

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants