Z. Zepos
Z. Zepos

Reputation: 87

crash on CPTScatterPlotDelegate in CorePlot

I am trying to overlay multiple graphs in one plot and I am getting crashes (EXC_BAD_ACCESS) on the CPTScatterPlotDelegate below in class CPTScatterPlot.m

-(void)renderAsVectorInContext:(nonnull CGContextRef)context {
    ...
    // Draw line
    if ( theLineStyle ) {
        CGPathRef dataLinePath = [self   newDataLinePathForViewPoints:viewPoints indexRange:viewIndexRange baselineYValue:CPTNAN];

        // Give the delegate a chance to prepare for the drawing.
        id<CPTScatterPlotDelegate> theDelegate = self.delegate;
       ....
    }
    ...
}

The Same in CPTLegendDelegate in class CPTPlot.m

-(void)drawSwatchForLegend:(nonnull CPTLegend *)legend atIndex:(NSUInteger)idx inRect:(CGRect)rect inContext:(nonnull CGContextRef)context
{
    id<CPTLegendDelegate> theDelegate = (id<CPTLegendDelegate>)self.delegate;
     ...
}

I am using CorePlot 2.1, and I have modified the renderInGraphHostingView in file SimpleScatterPlot.m in examples/CorePlotGallery as follows:

-(void)renderInGraphHostingView:(nonnull CPTGraphHostingView *)hostingView withTheme:(nullable CPTTheme *)theme animated:(BOOL)animated {
   ...
   static CPTGraph *graph = nil;
   if( initialize ) {
      graph = [[CPTXYGraph alloc] initWithFrame:bounds];
      ...
   }
   [self addGraph:graph toHostingView:hostingView];
   theme = [CPTTheme themeNamed:kCPTDarkGradientTheme];
   ...
}

So every time I want to draw a new line of data, I use the same graph.

The problem is random and sometimes program crashes when I draw the second line, sometimes in the third, but it always works fine for the first graph. It also depends on the compilation. Any ideas? Thanks in Advance

Upvotes: 0

Views: 65

Answers (1)

Eric Skroch
Eric Skroch

Reputation: 27381

The delegate property holds a weak reference to the delegate object. Make sure the delegate isn't being deallocated between graph updates.

Upvotes: 1

Related Questions