开发者

crash at drawInRect:rect, I've the solution but don't know how?

开发者 https://www.devze.com 2023-03-21 19:12 出处:网络
The app works fine with the iphone 开发者_开发问答simulator but when we run it in the actual iphone device it crashes at the following line:

The app works fine with the iphone 开发者_开发问答simulator but when we run it in the actual iphone device it crashes at the following line:

[ucdView.image drawInRect:rect];

I've searched and found the solution but I don't know how to solve as the time is very short when we have to present it on this Friday. Look at the following solution: Must drawInRect: for a separate context be executed on the main thread?

The part where this crash happen is in Sculpture.m inside viewDidLoad()

- (void)viewDidLoad{
[super viewDidLoad]; 

CLController = [[CoreLocationController alloc] init];
CLController.delegate = self;
[CLController.locMgr startUpdatingLocation];

currentLoc = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"redPin.png"]];

UIImage *ucdImage = [UIImage imageNamed:@"ucd.png"];
self.ucdView = [[UIImageView alloc] initWithImage:ucdImage];//creating a view for UCD image
ucdView.userInteractionEnabled = YES;

[self loadingFile];

UIScrollView *myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[myScrollView setMinimumZoomScale:0.35];
[myScrollView setMaximumZoomScale:2.0];
myScrollView.clipsToBounds = YES;
myScrollView.bounces = YES;
myScrollView.contentOffset = CGPointMake(1400, 700);
[myScrollView setContentSize:CGSizeMake(ucdImage.size.width, ucdImage.size.height)];
[myScrollView setDelegate:self];
[myScrollView addSubview:ucdView];//adding ucd view to scroll view
[self.view addSubview:myScrollView]; // adding scrollview to self.view main view
[myScrollView release];


//Drawing The Line
UIGraphicsBeginImageContext(ucdView.frame.size);
CGRect rect = CGRectMake(0, 0, ucdView.frame.size.width, ucdView.frame.size.height);
[ucdView.image drawInRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 3.0);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGFloat dashArray[] = {2,0,2,2};
CGContextSetLineDash(context, 3, dashArray, 5);
CGContextMoveToPoint(context,[self longt_to_x:[[path_array objectAtIndex:0] doubleValue]],[self lat_to_y:[[path_array objectAtIndex:1] doubleValue]]);
int path_length = [path_array count];
for(int i = 2; i<path_length; i = i+2){
    CGContextAddLineToPoint(context,[self longt_to_x:[[path_array objectAtIndex:i] doubleValue]],[self lat_to_y:[[path_array objectAtIndex:i+1] doubleValue]]);
}
CGContextStrokePath(context);
ucdView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

}

Thanks a million in advance...


You didn't say where exactly the crash was, but you have already created one image context with UIGraphicsBeginImageContext, and then you create another one with CGBitmapContextCreate. My guess is that the later one is the problem (getting the arguments right can be tricky) and isn't what you want anyway. So change it to:

// Get the current drawing context which is the image context right now
CGContextRef context = UIGraphicsGetCurrentContext();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号