1

I am using Bezier path object to draw line and dashed line. I saved those paths in a file and used NScoder to persist those path Its working fine in iOS 6 device and iOS 7 simulator but throwing EXC_ARM_DA_ALIGN error in iOS 7 device for dashed Line not for plain line.

The dashed line is working fine at draw time, but when I navigate back to previous page and come to the Drawing view again, at that time it's crashed. I debugged the code and found that it is crashing while decoding the dashed line in the decoder method of "Line_Point.m" file

//To persist the path

import "Line_Point.h"

@implementation Line_Point
@synthesize point;
@synthesize line_color;
@synthesize line_pattern;
@synthesize path;

-(void)encodeWithCoder:(NSCoder *)encoder
{
    //Encode the properties of the object
    [encoder encodeObject:self.line_pattern forKey:@"line_pattern"];
    [encoder encodeObject:self.line_color forKey:@"line_color"];
    [encoder encodeObject:self.point forKey:@"point"];
    [encoder encodeObject:self.path forKey:@"path"];
}

-(id)initWithCoder:(NSCoder *)decoder
{
    self = [super init];
    if ( self != nil )
    {
        //decode the properties
        self.line_pattern = [decoder decodeObjectForKey:@"line_pattern"];
        self.line_color = [decoder decodeObjectForKey:@"line_color"];
        self.point = [decoder decodeObjectForKey:@"point"];
        self.path = [decoder decodeObjectForKey:@"path"];// this is where i got the   EXC_ARM_DA_ALIGN error
    }
    return self;
}

// To draw line:

In CanvasViewDirectionalLines.m

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
        myPath = [UIBezierPath bezierPath] ;
        UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
        [myPath moveToPoint:[mytouch locationInView:self]];

        Line_Point * to_be_added = [[Line_Point alloc] init];
        to_be_added.line_color = [UIColor colorWithCGColor: current_color.CGColor];
        to_be_added.line_pattern = [NSString stringWithString: current_line_pattern];
        if ([to_be_added.line_pattern isEqualToString:@"normal"])
        {
            [myPath setLineWidth:1.0];
            [myPath setLineDash:0 count:0 phase:0];
        }
        else if([to_be_added.line_pattern isEqualToString:@"thick"])
        {
            [myPath setLineWidth:3.0];
            [myPath setLineDash:0 count:0 phase:0];
        }

        else if([to_be_added.line_pattern isEqualToString:@"dotted"])
        {
            CGFloat newLocations[kMyClassLocationCount] = {6.0, 2.0};
            myInstance.patterns = newLocations;
            [myInstance setPatterns:newLocations];
            [myPath setLineWidth:2.0];
            //CGFloat Pattern1[] = {6.0, 2.0};
            //CGFloat *Pattern1 = myInstance.patterns;
            [myPath setLineDash:myInstance.patterns count:2 phase:0];
        }
        else if([to_be_added.line_pattern isEqualToString:@"super_dotted"])
        {

            [myPath setLineWidth:2.0];
            float Pattern[4] = {1, 2, 1, 2};
            [myPath setLineDash:Pattern count:4 phase:0];
        }
        to_be_added.path = myPath;
        [pathArray addObject:to_be_added];
        [track_of_activites addObject:@"freeform_tool"];
 }

In Drawrect:

-(void)drawRect:(CGRect)rect
{
    for(int i=0; i<pathArray.count; i++){
        Line_Point * first = [[pathArray objectAtIndex:i] retain];
        [first.line_color  setStroke];
        [first.path stroke];
    }
}

I have been trying to solve this issue for 3 days. Please help me

meera
  • 53
  • 2
  • 9
  • when you encode, is self.point a CGPoint? what are the types of the things you encode before the bezier? – adam.wulf Aug 09 '14 at 17:38

1 Answers1

1

I know this is an old question, but just in case you were still working on it,

Have you tried changing:

float Pattern[4] = {1, 2, 1, 2}; [myPath setLineDash:Pattern count:4 phase:0];

to use a CGFloat instead of a float (as this should be what the setLineDash method is expecting) in your super_dotted drawing method. Something like this:

[myPath setLineWidth:2.0]; CGFloat Pattern[4] = {1, 2, 1, 2}; [myPath setLineDash:Pattern count:4 phase:0];