2015-05-07 4 views
0

Я получаю сообщения от пользователей моего приложения об ошибке внутри структуры CorePlot. Это не всегда происходит, и я не могу обнаружить шаблон, как заставить его разбиться. Я хотел бы знать, есть ли что-то, что я могу сделать, чтобы избежать этого краха.Ошибка в CorePlot 1.5.1

Exception Type: SIGSEGV 
Exception Codes: SEGV_MAPERR at 0x4c69ef75bec0 
Crashed Thread: 0 

Application Specific Information: 
Selector name found in current argument registers: retain 

Thread 0 Crashed: 
0 libobjc.A.dylib      0x00007fff885c80dd objc_msgSend + 29 
1 AppKit        0x00007fff8f045916 +[NSGraphicsContext setCurrentContext:] + 76 
2 CorePlot        0x0000000104f10119 CPTPopCGContext + 40 
3 CorePlot        0x0000000104f10051 -[NSAttributedString(CPTPlatformSpecificAttributedStringExtensions) drawInRect:inContext:] + 80 
4 CorePlot        0x0000000104f05822 -[CPTTextLayer renderAsVectorInContext:] + 513 
5 CorePlot        0x0000000104f06058 -[CPTLayer drawInContext:] + 55 
6 QuartzCore       0x00007fff82dfe0c3 _ZN2CA5Layer8display_Ev + 657 
7 QuartzCore       0x00007fff82dfc7fd _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 603 
8 QuartzCore       0x00007fff82dfbe81 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 35 
9 QuartzCore       0x00007fff82dfb612 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242 
10 QuartzCore       0x00007fff82dfb3ae _ZN2CA11Transaction6commitEv + 390 
11 QuartzCore       0x00007fff82e09f19 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 71 
12 CoreFoundation      0x00007fff8b53f127 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23 
13 CoreFoundation      0x00007fff8b53f080 __CFRunLoopDoObservers + 368 
14 CoreFoundation      0x00007fff8b530bf8 CFRunLoopRunSpecific + 328 
15 HIToolbox       0x00007fff9130f56f RunCurrentEventLoopInMode + 235 
16 HIToolbox       0x00007fff9130f2ea ReceiveNextEventCommon + 431 
17 HIToolbox       0x00007fff9130f12b _BlockUntilNextEventMatchingListInModeWithFilter + 71 
18 AppKit        0x00007fff8f0719bb _DPSNextEvent + 978 
19 AppKit        0x00007fff8f070f68 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 346 
20 AppKit        0x00007fff8f066bf3 -[NSApplication run] + 594 
21 AppKit        0x00007fff8efe3354 NSApplicationMain + 1832 
22 MyApp        0x0000000104afcc3a main (ReceiptCheck.h:4779) 
23 libdyld.dylib      0x00007fff830fd5c9 start + 1 

Я использую CorePlot для 2-х типов графики: а пирог и гистограмме отобразить 2 одновременно, посмотрите:

enter image description here

Мое приложение использует ARC и работает только в Йосемити. Вот мой код:

-(void)createGraphs{ 
    [self updateChartTextStyles]; 

    self.completedGraph = [self createGraphWithHostView:self.completedGraphHostingView]; 
    self.uncompletedGraph = [self createGraphWithHostView:self.uncompletedGraphHostingView]; 
} 

-(CPTXYGraph *)createGraphWithHostView:(CPTGraphHostingView *)hostView{ 
    CPTXYGraph *graph = [[CPTXYGraph alloc]initWithFrame:self.completedGraphHostingView.bounds]; 
    graph.plotAreaFrame.fill = [CPTFill fillWithColor:[CPTColor clearColor]]; 
    graph.paddingBottom = 0; 
    graph.paddingTop = 0; 
    graph.paddingLeft = 0; 
    graph.paddingRight = 0; 
    graph.masksToBorder = NO; 
    [graph setTitleTextStyle:self.chartTitleStyle]; 
    hostView.hostedGraph = graph; 
    return graph; 
} 

-(void)updateChartTextStyles{ 
    CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle]; 
    textStyle.fontName = [[ThemeManager mainFont] labelFont].fontName; 
    textStyle.fontSize = [[[ThemeManager mainFont] labelFont] pointSize]; 
    textStyle.color = [CPTColor colorWithCGColor:[NSColor blackColor].CGColor]; 

    self.chartLabelStyle = textStyle; 

    textStyle = [CPTMutableTextStyle textStyle]; 
    textStyle.fontName = [[ThemeManager mainFont].titleFont fontName]; 
    textStyle.fontSize = [[ThemeManager mainFont].titleFont pointSize]; 
    textStyle.color = [CPTColor colorWithCGColor:[NSColor blackColor].CGColor]; 

    self.chartTitleStyle = textStyle; 
} 

-(void)removeAllPlotsInGraph:(CPTGraph *)graph{ 
    NSArray *allPlots = [graph.allPlots copy]; 
    for (CPTPlot *plot in allPlots) { 
     [graph removePlot:plot]; 
    } 
} 

-(void)setPieChartPlotToGraph:(CPTGraph *)graph withIdentifier:(NSString *)identifier{ 
    [self removeAllPlotsInGraph:graph]; 
    CPTPieChart *pieChart = [[CPTPieChart alloc]init]; 
    pieChart.dataSource = self; 
    pieChart.delegate = self; 
    pieChart.pieRadius = (graph.hostingView.bounds.size.height*.7)/2; 
    pieChart.identifier = identifier; 
    CPTMutableShadow *shadow = [CPTMutableShadow shadow]; 
    shadow.shadowColor = [CPTColor colorWithCGColor:[NSColor grayColor].CGColor]; 
    shadow.shadowBlurRadius = 3; 
    shadow.shadowOffset = CGSizeMake(1, -1); 
    [pieChart setShadow:shadow]; 

    graph.plotAreaFrame.paddingTop   = 0; 
    graph.plotAreaFrame.paddingRight  = 0; 
    graph.plotAreaFrame.paddingBottom  = 0; 
    graph.plotAreaFrame.paddingLeft   = 0; 

    [graph.axisSet setHidden:YES]; 

    CPTXYPlotSpace *plotSpace  = (CPTXYPlotSpace *)graph.defaultPlotSpace; 
    plotSpace.yRange    = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) 
                    length:CPTDecimalFromInt(10)]; 
    plotSpace.xRange    = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) 
                    length:CPTDecimalFromInt(10)]; 

    [graph addPlot:pieChart]; 
} 

-(CPTBarPlot *)createBarPlotWithIdentifier:(NSString *)identifier withColor1:(NSColor *)color1 andColor2:(NSColor *)color2{ 
    CPTBarPlot *barChart = [[CPTBarPlot alloc]init]; 
    barChart.paddingBottom = 0; 
    barChart.paddingLeft = 0; 
    barChart.paddingRight = 0; 
    barChart.paddingTop = 0; 
    barChart.dataSource = self; 
    barChart.delegate = self; 
    barChart.identifier = identifier; 
    barChart.barWidth = CPTDecimalFromFloat(.7); 
    barChart.barCornerRadius = 6; 
    barChart.lineStyle = nil; 

    CPTMutableShadow *shadow = [CPTMutableShadow shadow]; 
    shadow.shadowColor = [CPTColor grayColor]; 
    shadow.shadowBlurRadius = 3; 
    shadow.shadowOffset = CGSizeMake(1, -1); 
    [barChart setShadow:shadow]; 

    CPTGradient *gradient = [CPTGradient gradientWithBeginningColor:[CPTColor colorWithCGColor:color1.CGColor] endingColor:[CPTColor colorWithCGColor:color2.CGColor]]; 
    barChart.fill = [CPTFill fillWithGradient:gradient]; 
    return barChart; 
} 

-(void)setBarPlotToGraph:(CPTGraph *)graph withIdentifier:(NSString *)identifier andComposedColor:(ComposedColor *)composedColor{ 

    [self removeAllPlotsInGraph:graph]; 

    graph.plotAreaFrame.paddingTop   = 10.0; 
    graph.plotAreaFrame.paddingRight  = 0.00; 
    graph.plotAreaFrame.paddingBottom  = 30.0; 
    graph.plotAreaFrame.paddingLeft   = 0; 


    [graph addPlot:[self createBarPlotWithIdentifier:identifier withColor1:composedColor.baseColor andColor2:composedColor.brightColor]]; 


    CPTXYPlotSpace *plotSpace  = (CPTXYPlotSpace *)graph.defaultPlotSpace; 
    plotSpace.yRange    = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) 
                    length:CPTDecimalFromInt(15)]; 
    plotSpace.xRange    = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-1) 
                    length:CPTDecimalFromInt(8)]; 

    CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet; 
    CPTXYAxis *xAxis = axisSet.xAxis; 
    xAxis.orthogonalCoordinateDecimal = CPTDecimalFromInt(0); 
    xAxis.majorIntervalLength = CPTDecimalFromInt(1); 
    xAxis.minorTicksPerInterval = 0; 
    xAxis.labelingPolicy = CPTAxisLabelingPolicyNone; 
    xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0]; 



    NSArray *dayOfWeekLabels = [NSDate daysOfTheWeekNamesAbbreviated:YES]; 
    NSMutableArray *customXLabels = [NSMutableArray array]; 
    NSDate *tempDate = self.startDate; 
    for (int i = 0; i < 7; i++) { 
     CPTAxisLabel *label = [[CPTAxisLabel alloc]initWithText:[NSString stringWithFormat:@"%@ %i",dayOfWeekLabels[i], tempDate.day] textStyle:self.chartLabelStyle]; 
     tempDate = [tempDate addDays:1]; 
     label.tickLocation = [@(i) decimalValue]; 
     label.offset = xAxis.labelOffset + xAxis.majorTickLength; 
//  label.rotation = M_PI/4.0; 
     [customXLabels addObject:label]; 
    } 

    xAxis.axisLabels = [NSSet setWithArray:customXLabels]; 

    CPTXYAxis *yAxis = axisSet.yAxis; 
    yAxis.title = @"Value"; 
    yAxis.titleOffset = 50.f; 
    yAxis.labelingPolicy = CPTAxisLabelingPolicyNone; 
    yAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0]; 


} 

-(void)updateCharts{ 
    [self updateCompletedChart]; 
    [self updateUncompletedChart]; 
} 

-(void)updateUncompletedChart{ 

    self.uncompletedTasksGraphData = [self calculateChartDataWithTasks:self.uncompletedTasks groupType:[self groupTypeForGraph] chartType:[self chartTypeForGraph]]; 

    if (self.pieChartButton.state) { 
     [self setPieChartPlotToGraph:self.uncompletedGraph withIdentifier:UNCOMPLETED_PIE_CHART_IDENTIFIER]; 
    } 
    else if(self.barChartButton.state){ 
     [self setBarPlotToGraph:self.uncompletedGraph withIdentifier:UNCOMPLETED_BAR_CHART_IDENTIFIER andComposedColor:[[ComposedColorManager defaultInstance]composedColorWithCode:@"Red"]]; 
    } 

    [self.uncompletedGraph reloadData]; 
} 

-(void)updateCompletedChart{ 

    self.completedTasksGraphData = [self calculateChartDataWithTasks:self.completedTasks groupType:[self groupTypeForGraph] chartType:[self chartTypeForGraph]]; 

    if (self.pieChartButton.state) { 
     [self setPieChartPlotToGraph:self.completedGraph withIdentifier:COMPLETED_PIE_CHART_IDENTIFIER]; 
    } 
    else if(self.barChartButton.state){ 
     [self setBarPlotToGraph:self.completedGraph withIdentifier:COMPLETED_BAR_CHART_IDENTIFIER andComposedColor:[[ComposedColorManager defaultInstance]composedColorWithCode:@"Green"]]; 
    } 


    [self.completedGraph reloadData]; 
} 



///////////////////////////////////////////////////////////// 
#pragma mark Graph Data Source 
///////////////////////////////////////////////////////////// 

-(NSMutableArray *)chartDataForIdentifier:(NSString *)identifier{ 
    if (identifier == COMPLETED_PIE_CHART_IDENTIFIER || identifier == COMPLETED_BAR_CHART_IDENTIFIER) { 
     return self.completedTasksGraphData; 
    } 
    else if(identifier == UNCOMPLETED_PIE_CHART_IDENTIFIER || identifier == UNCOMPLETED_BAR_CHART_IDENTIFIER){ 
     return self.uncompletedTasksGraphData; 
    } 
    else{ 
     throwNotImplementedException; 
    } 
} 


-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot{ 
    if (plot.identifier == COMPLETED_PIE_CHART_IDENTIFIER || plot.identifier == UNCOMPLETED_PIE_CHART_IDENTIFIER) { 
     return [[self chartDataForIdentifier:(NSString *)plot.identifier] count]; 
    } 
    else{ 
     return 7; 
    } 
} 

-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx{ 
    if (plot.identifier == COMPLETED_PIE_CHART_IDENTIFIER || plot.identifier == UNCOMPLETED_PIE_CHART_IDENTIFIER) { 
     if (fieldEnum == CPTPieChartFieldSliceWidth) { 
      NSMutableArray *graphData = [self chartDataForIdentifier:(NSString *)plot.identifier]; 
      return [graphData[idx] numberValue]; 
     } 
     else{ 
      return @(0); 
     } 
    } 
    else if(plot.identifier == COMPLETED_BAR_CHART_IDENTIFIER || plot.identifier == UNCOMPLETED_BAR_CHART_IDENTIFIER){ 
     if (fieldEnum == CPTScatterPlotFieldX) { 
      return @(idx); 
     } 
     else if(fieldEnum == CPTScatterPlotFieldY){ 
      NSDate *date = [self.startDate addDays:idx]; 
      NSMutableArray *graphData = [self chartDataForIdentifier:(NSString *)plot.identifier]; 
      float sum = [graphData chartDataSumWithDate:date]; 
      return @(sum); 
     } 
     else{ 
      return @(0); 
     } 
    } 
    else{ 
     throwNotImplementedException; 
    } 
} 

-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)idx{ 


    if (plot.identifier == COMPLETED_PIE_CHART_IDENTIFIER || plot.identifier == UNCOMPLETED_PIE_CHART_IDENTIFIER) { 
     NSMutableArray *chartDataArray = [self chartDataForIdentifier:(NSString *)plot.identifier]; 

     ChartData *chartData = chartDataArray[idx]; 
     CPTTextLayer *textLayer = [[CPTTextLayer alloc]initWithText:[chartData labelWithPercentage]]; 
     [textLayer setTextStyle:self.chartLabelStyle]; 
     return textLayer; 
    } 
    else{ 
     NSMutableArray *chartData = [self chartDataForIdentifier:(NSString *)plot.identifier]; 
     NSDate *date = [[self.startDate addDays:idx] dateAsDateWithoutTime]; 
     float sum = [chartData chartDataSumWithDate:date]; 
     if (sum == 0) { 
      return nil; 
     } 
     CPTTextLayer *textLayer = [[CPTTextLayer alloc]initWithText:[NSString stringWithFormat:@"%.0f", sum]]; 
     return textLayer; 
    } 


} 

-(CPTFill *)sliceFillForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index{ 
    if (pieChart.identifier == COMPLETED_PIE_CHART_IDENTIFIER || pieChart.identifier == UNCOMPLETED_PIE_CHART_IDENTIFIER) { 
     NSMutableArray *chartData = [self chartDataForIdentifier:(NSString *)pieChart.identifier]; 
     ChartData *data = chartData[index]; 
     if (data.color && data.color2) { 
      CPTColor *cptColor1, *cptColor2; 
      cptColor1 = [CPTColor colorWithCGColor:data.color.CGColor]; 
      cptColor2 = [CPTColor colorWithCGColor:data.color2.CGColor]; 
      CPTGradient *gradient = [CPTGradient gradientWithBeginningColor:cptColor1 endingColor:cptColor2]; 
      return [CPTFill fillWithGradient:gradient]; 
     } 
     else{ 
      CPTColor *color = [CPTColor colorWithCGColor:data.color.CGColor]; 
      CPTFill *fill = [CPTFill fillWithColor:color]; 
      return fill; 
     } 
    } 
    else{ 
     throwNotImplementedException; 
    } 
} 

ответ

1

Я считаю, что проблема была решена. В ближайшее время выйдет релиз 1.6, или вы можете вывести последний код с GitHub.

Смежные вопросы