My ios app rebooting the system ios 7

Discussion in 'iOS Programming' started by florind, Apr 1, 2014.

  1. florind macrumors newbie

    Joined:
    Apr 1, 2014
    #1
    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.
    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;
    }
     
  2. Menneisyys2 macrumors 603

    Joined:
    Jun 7, 2011
    #2
    Could you create an Xcode project only having this code (no trade secrets etc.) and making sure it does crash your customer's device? I have tons of iOS7 devices around - I can give each a try.
     
  3. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #3
    No BugSense report would presumably be because the phone reboots (as opposed to App crash).

    The iOS CrashReporter likely creates a report (at boot time) for this scenario.

    Do you see crash reports in iTunes Connect?
     
  4. CyberGeek macrumors member

    Joined:
    Jun 30, 2007
    #4
    Does your view support multi-touch? If it does, you have some problems.

    1) User puts finger A on the screen
    - touchesBegan:withEvent: gets called
    - createNewLayerAndPath gets called
    - _drawingPath gets assigned to a new mutable path

    2) User puts finger B on the screen
    - touchesBegan:withEvent: gets called
    - createNewLayerAndPath gets called
    - _drawingPath gets assigned to a new mutable path. The previous object that _drawingPath referenced presumably gets dropped entirely, and its memory probably leaks.

    3) User lifts finger A from the screen
    - touchesEnded:withEvent: gets called
    - CGPathRelease gets called on the object pointed to by _drawingPath, which might deallocate it, but you don't set the _drawingPath pointer to nil immediately after, so you may be referencing a deallocated object at this point

    4) User lifts finger B from the screen
    - touchesEnded:withEvent: gets called
    - CGPathRelease gets called on the object pointed to by _drawingPath. Since that object may very well be the object that was deallocated in 3), you maybe be calling CGPathRelease on deallocated memory, which, best case, results in a crash.
     
  5. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #5
    Nice explanation. And this is certainly a bug -- it is enough to bring the whole system down? It should not be, since the OS provides memory protection. Maybe some kernel bug gets tickled?
     
  6. CyberGeek macrumors member

    Joined:
    Jun 30, 2007
    #6
    Nothing in there strikes me as enough to crash the entire system. At the same time, though, *nothing* in an iOS app should be able to crash the entire system, obviously, though such bugs do exist.

    That said, CGPaths and CALayers live pretty close to the OS windowing system. Historically, doing bad things to the OS windowing system (like deallocating a view's drawing context within app code) has sometimes been known to cause issues at the OS level. If he's deallocating a CGPath that's referenced by a CALayer that exists in the on-screen layer hierarchy, that could cause problems when the OS goes in to draw the layer hierarchy.
     
  7. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #7
    If you implement any of the four touches methods you're supposed to implement all of them. touchesCanceled isn't implemented here.

    If you can't solve the problem I would add some logging to your code and then get the logs from your customer.
     

Share This Page