1

I have an app that works fine in the debug mode on the device. I sent the app to the App Store and it works fine, except for iPhone 3G.

My test(debug) device is an iPhone 3G and it works just fine in debug, but when I downloaded the app and installed it via the App Store, it didn't work on my iPhone as well.

I had some NSLogs in the code and thought that that might be the problem, but even after the removal of NSLog, the same thing happens on iPhone 3G.

The problem is that I'm using the following code:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    mouseSwiped = YES;

    UITouch *touch = [touches anyObject];   
    CGPoint currentPoint = [touch locationInView:self.view];
    currentPoint.y -= 20;


    UIGraphicsBeginImageContext(self.view.frame.size);
    [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    lastPoint = currentPoint;

}

and on an iPhone 3G this does not draw right. It just makes horizontal lines. This works fine on other devices.

What could be going wrong here?

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
iPhoneNoob
  • 173
  • 1
  • 6
  • 19

2 Answers2

3

There is a known bug with the LLVM compiler in Xcode 4.2 that leads to incorrect results when using CGPoints, etc. on the ARMv6 architecture. This is detailed in this thread on the Apple Developer Forums. ARMv6 is what is used for pre-iPhone 3G S devices (such as your iPhone 3G), so that's why you'd see it there.

The bug is related to incorrect Thumb code generation for the ARMv6 builds of your application. I describe how to selectively disable Thumb for just that older architecture (while preserving performance on the unaffected ARMv7 build) in my answer here.

Some people have said that Xcode 4.2.1 has a fixed version of LLVM which addresses this, but I can't confirm that. Read gparker's comment near the end of this Apple Developer Forum thread to see where this has been fixed.

Community
  • 1
  • 1
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
2

I have suffered similar issues. I discovered that a lot of that kind of troubles are originated by a buggy optimization made by Xcode for armv6 architecture.

In "Build Settings" -> "Apple LLMV Compiler 3.0 - code generation" -> "Optimization Level" you surely have an optimization setting for Release version. Change it and set it to NONE as Debug version is for sure.

That is all. If the problem is what I think it is, then that is the solution. You can test this solution building Adhoc app.

Gabriel
  • 3,319
  • 1
  • 16
  • 21
  • Thanks for the tip! I'll try it out and let U know! – iPhoneNoob Dec 21 '11 at 15:00
  • 2
    I experienced the same issue with armv6 code. In Xcode you can set the optimization level for every file, so you don't have to disable the optimization for the entire app. 'Your Target' -> 'Build Phases' -> 'Compile Sources' there you have a column 'Compiler Flags' just set it to -O0 on the files you have the problem. – V1ru8 Dec 21 '11 at 15:24