I have a strange problem with my app , my client is complaing about my app is crashing randomly and the phone is rebooting ! I have bugsense installed on phone and i don't receive any bug report for this problem . The problem appear on the drawing screen , where i'm use SGPATH for record the drawing points.
I attached the code for the drawing screen: Thanks in advance, and have a nice day.
I attached the code for the drawing screen: Thanks in advance, and have a nice day.
Code:
- (void)undo
{
if(!_layersArray || _layersArray.count == 0)
return;
CAShapeLayer *lastLayer = [_layersArray lastObject];
[lastLayer removeFromSuperlayer];
[_layersArray removeLastObject];
}
}
-(void)selectWidth:(int)tag
{
self.width = tag;
}
-(void)selectColor:(int)tag
{
if(tag == 0){
self.color = [UIColor colorWithRed:235.0/255.0 green:235.0/255.0 blue:240.0/255.0 alpha:1];
}else if(tag == 1){
self.color = [UIColor colorWithRed:37.0/255.0 green:37.0/255.0 blue:41.0/255.0 alpha:1];
}
}
#pragma mark -
#pragma mark Factory
- (void) createNewLayerAndPath
{
_drawingLayer = [CAShapeLayer layer];
_drawingLayer.strokeColor = self.color.CGColor;
_drawingLayer.fillColor = [UIColor clearColor].CGColor;
_drawingLayer.lineWidth = self.width;
_drawingLayer.lineJoin = kCALineJoinRound;
_drawingLayer.lineCap = kCALineCapRound;
[self.layer addSublayer:_drawingLayer];
_drawingPath = CGPathCreateMutable();
[_layersArray addObject:_drawingLayer];
}
#pragma mark -
#pragma mark Calculation Of Middle Points
CGPoint midPoint(CGPoint p1 , CGPoint p2){
return CGPointMake((p1.x + p2.x)*0.5, (p1.y + p2.y)*0.5);
}
#pragma mark -
#pragma mark Touches
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if (self.delegate && [self.delegate respondsToSelector:@selector(viewTouched)]){
[self.delegate viewTouched];
}
[self createNewLayerAndPath];
UITouch *touch = [touches anyObject];
CGPoint firstPoint = [touch locationInView:self];
CGPathMoveToPoint(_drawingPath, NULL, firstPoint.x, firstPoint.y);
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
_currentPoint = [touch locationInView:self];
_previousPoint = [touch previousLocationInView:self];
CGPoint midpoint2 = midPoint(_currentPoint, _previousPoint);
CGPathAddQuadCurveToPoint(_drawingPath, nil, _previousPoint.x, _previousPoint.y, midpoint2.x, midpoint2.y);
[_drawingLayer setPath:NULL];
[_drawingLayer setPath:_drawingPath];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
_currentPoint = [touch locationInView:self];
_previousPoint = [touch previousLocationInView:self];
CGPoint midpoint2 = midPoint(_currentPoint, _previousPoint);
CGPathAddQuadCurveToPoint(_drawingPath, nil, _previousPoint.x, _previousPoint.y, midpoint2.x, midpoint2.y);
[_drawingLayer setPath:NULL];
[_drawingLayer setPath:_drawingPath];
if(_drawingPath != NULL)
CGPathRelease(_drawingPath);
_drawingLayer = nil;
}