Crash after -[ShinobiChart layoutSubviews]


#1

Hi everyone!

i have a horrible app crash with follow stack trace:

0 CoreFoundation 0x0000000105eeaa75 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000105772bb7 objc_exception_throw + 45 2 CoreFoundation 0x0000000105db90ca -[__NSArrayM insertObject:atIndex:] + 954 3 MyApp 0x00000001047e4f07 -[SChartDataLoader appendDataPoints:toSeries:withIndex:numberOfPointsToRemoveFromStart:xAxis:yAxis:] + 759 4 MyApp 0x000000010475d20b -[SChartSeries appendDataOnChart:fromDatasource:xAxis:yAxis:seriesIndex:] + 315 5 MyApp 0x00000001047a5f17 -[ShinobiChart layoutSubviews] + 2487 6 UIKit 0x00000001063541c3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521 7 QuartzCore 0x000000010516bc58 -[CALayer layoutSublayers] + 150 8 QuartzCore 0x000000010516087e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380 9 QuartzCore 0x00000001051606ee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 10 QuartzCore 0x00000001050ce36e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242 11 QuartzCore 0x00000001050cf482 _ZN2CA11Transaction6commitEv + 390 12 UIKit 0x00000001062d7286 _UIApplicationHandleEventQueue + 2140 13 CoreFoundation 0x0000000105e1fc91 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 14 CoreFoundation 0x0000000105e15b5d __CFRunLoopDoSources0 + 269 15 CoreFoundation 0x0000000105e15194__ CFRunLoopRun + 868 16 CoreFoundation 0x0000000105e14bc6 CFRunLoopRunSpecific + 470 17 GraphicsServices 0x0000000108a99a58 GSEventRunModal + 161 18 UIKit 0x00000001062da580 UIApplicationMain + 1282 19 MyApp 0x0000000104700943 main + 115 20 libdyld.dylib 0x000000010774a145 start + 1 21 ??? 0x0000000000000001 0x0 + 1

Something about my chart. 

Initialisation:

    self.shinobiChart.clipsToBounds = NO;
     self.shinobiChart.backgroundColor = [UIColorclearColor];
     self.shinobiChart.userInteractionEnabled = NO;
     self.shinobiChart.plotAreaBackgroundColor = [UIColorclearColor];
    
     SChartDateRange* xRange = [[SChartDateRangealloc] initWithDateMinimum:[[NSDatedate] dateByAddingTimeInterval:-100]
                                                            andDateMaximum:[NSDate date]];
     SChartDateTimeAxis * xAxis = [[SChartDateTimeAxisalloc] initWithRange:xRange];
 
     SChartAxisStyle * xAxisStyle = [SChartAxisStylenew];
    xAxisStyle.lineWidth = 0;
    xAxisStyle.lineColor = [UIColor clearColor];
     SChartMajorGridlineStyle* xMajorLineStyle = [SChartMajorGridlineStylenew];
     xMajorLineStyle.lineColor = [_sharedColorProvidergraphXAxisGridColor];
    xMajorLineStyle.lineWidth = @(1);
    xMajorLineStyle.dashStyle = @[@(1), @(1)];
    xMajorLineStyle.showMajorGridLines = YES;
    xMajorLineStyle.dashedMajorGridLines = YES;
    xAxisStyle.majorGridLineStyle = xMajorLineStyle;
    xAxis.style = xAxisStyle;
     self.shinobiChart.xAxis = xAxis;
    
     SChartNumberRange* yRange = [[SChartNumberRangealloc] initWithMinimum:@(-10)andMaximum:@(20)];
     SChartNumberAxis * yAxis = [[SChartNumberAxisalloc] initWithRange:yRange];
     SChartAxisStyle * yAxisStyle = [SChartAxisStylenew];
    yAxisStyle.lineWidth = 0;
    yAxisStyle.lineColor = [UIColor clearColor];
     SChartMajorGridlineStyle* yMajorLineStyle = [SChartMajorGridlineStylenew];
     yMajorLineStyle.lineColor = [_sharedColorProvidergraphYAxisGridColor];
    yMajorLineStyle.lineWidth = @(.5);
    yMajorLineStyle.dashStyle = @[@(1), @(1)];
    yMajorLineStyle.showMajorGridLines = YES;
    yMajorLineStyle.dashedMajorGridLines = YES;
    yAxisStyle.majorGridLineStyle = xMajorLineStyle;
    yAxis.style = yAxisStyle;
     self.shinobiChart.yAxis = yAxis;
     self.shinobiChart.legend.hidden = YES;
     self.shinobiChart.delegate = self;
 
     self.shinobiChart.datasource = self;

datasource:

-(NSInteger)numberOfSeriesInSChart:(ShinobiChart *)chart{
    return 2;
}
 
-(SChartSeries*)sChart:(ShinobiChart *)chart seriesAtIndex:(NSInteger)index{
     SChartLineSeries * lineSeries = [[SChartLineSeriesalloc] init];
     SChartLineSeriesStyle * lineStyle = [SChartLineSeriesStylenew];
    if (index == 1) {
        lineStyle.showFill = NO;
         lineStyle.lineColor = [_sharedColorProvidergraphActualLineColor];
        lineStyle.lineWidth = @(2);
    } else{
        lineStyle.showFill = YES;
        lineStyle.fillWithGradient = YES;
         lineStyle.areaColorLowGradient = [_sharedColorProvidergraphDesiredEndColor];
         lineStyle.areaColor = [_sharedColorProvidergraphDesiredStartColor];
        lineStyle.areaLineColor = [UIColor clearColor];
    }
    [lineSeries setStyle:lineStyle];
    return lineSeries;
}
 
-(NSInteger)sChart:(ShinobiChart *)chart numberOfDataPointsForSeriesAtIndex:(NSInteger)seriesIndex{
     return_actualPoints.count;
}
 
-(id<SChartData>)sChart:(ShinobiChart *)chart dataPointAtIndex:(NSInteger)dataIndex forSeriesAtIndex:(NSInteger)seriesIndex{
    
    if (seriesIndex == 1) {
        return _actualPoints[dataIndex];
    } else{
        return _desiredPoints[dataIndex];
    }
}
 
delegate:
-(void)sChartRenderStarted:(ShinobiChart *)chart withFullRedraw:(BOOL)fullRedraw{
     _renderFinished = NO;
}
 
-(void)sChartRenderFinished:(ShinobiChart *)chart{
     _renderFinished = YES;
 
}
 
adding new data:
//this method called with frequency twice per sec
-(void)pidsStatisticManager:(WTPidsStatisticManager *)manager changedActualArray:(NSArray *)actualArray andDesiredArray:(NSArray *)desiredArray{
    
     if (!_renderFinished) {
        return;
    }
    
     [self.shinobiChart.xAxissetDefaultRange:[[SChartDateRangealloc] initWithDateMinimum:[NSDatedateWithTimeIntervalSinceNow:-manager.maximumPointsCount * manager.timeInterval]
                                                                           andDateMaximum:[NSDate date]]];
    
    NSInteger oldArrayCount = _actualPoints.count;
    _actualPoints = [NSMutableArray arrayWithArray:actualArray];
    _desiredPoints = [NSMutableArray arrayWithArray:desiredArray];
    if (actualArray.count < manager.maximumPointsCount &&
        actualArray.count == oldArrayCount + 1) {
         [self.shinobiChartappendNumberOfDataPoints:1toEndOfSeriesAtIndex:0];
         [self.shinobiChartappendNumberOfDataPoints:1toEndOfSeriesAtIndex:1];
    } else if (oldArrayCount < actualArray.count){
        [self.shinobiChart reloadData];
    } else if (actualArray.count == manager.maximumPointsCount){
         [self.shinobiChartremoveNumberOfDataPoints:1fromStartOfSeriesAtIndex:0];
         [self.shinobiChartremoveNumberOfDataPoints:1fromStartOfSeriesAtIndex:1];
         [self.shinobiChartappendNumberOfDataPoints:1toEndOfSeriesAtIndex:0];
         [self.shinobiChartappendNumberOfDataPoints:1toEndOfSeriesAtIndex:1];
    }
     [self.shinobiChartredrawChart];
 
}
 
 
also I have strange log on loading my view with graph:
 The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
 2015-03-19 18:20:33.123 WiTune[6561:384273] ShinobiCharts: Attempting to update axis data range with nil series min or max. Axis range not updated.
 From: SChartDateTimeAxis at 0x7fac725d59e0, axisRange = { 0.000000, 1.000000 }, defaultRange = { 2015-03-19 14:18:52 +0000, 2015-03-19 14:20:32 +0000 }, maxRange = { 1970-01-01 00:00:00 +0000, 1970-01-01 00:00:01 +0000 }
 2015-03-19 18:20:33.123 WiTune[6561:384273] ShinobiCharts: Attempting to update axis data range with nil series min or max. Axis range not updated.
 From: SChartNumberAxis at 0x7fac725da180, axisRange = { 0.000000, 1.000000 }, defaultRange = { 0.000000, 1.000000 }, maxRange = { 0.000000, 1.000000 }
 2015-03-19 18:20:33.124 WiTune[6561:384273] ShinobiCharts: Attempting to update axis data range with nil series min or max. Axis range not updated.
 From: SChartDateTimeAxis at 0x7fac725d59e0, axisRange = { 0.000000, 1.000000 }, defaultRange = { 2015-03-19 14:18:52 +0000, 2015-03-19 14:20:32 +0000 }, maxRange = { 1970-01-01 00:00:00 +0000, 1970-01-01 00:00:01 +0000 }
 2015-03-19 18:20:33.124 WiTune[6561:384273] ShinobiCharts: Attempting to update axis data range with nil series min or max. Axis range not updated.
 
 From: SChartNumberAxis at 0x7fac725da180, axisRange = { 0.000000, 1.000000 }, defaultRange = { 0.000000, 1.000000 }, maxRange = { 0.000000, 1.000000 }
 
  
Please help me with this problem!

#2

Hi Eric,

Thanks for getting in touch with us and apologies it took a while to get back to you.

Unfortunately this looks like a known issue with our appendData functionality which we hope to resolve shortly. As a workaround, you should be able to append your new datapoint to your dataset (e.g. your _actualPoints and _desiredPoints arrays), then reload and redraw the chart.

If you’re seeing this crash regularly, it would be great if you could send your dataset to us at info@shinobicontrols.com as it could help us narrow down the cause of the issue.

Please get back to us if you have any further difficulties with this.

Kind regards,

Sam