How to Set Cg_Context_Show_Backtrace Environmental Variable

How can I set CG_CONTEXT_SHOW_BACKTRACE environmental variable?

It's a bug in 9b5:

https://forums.developer.apple.com/thread/13683

File a RADAR with Apple.

please set CG_CONTEXT_SHOW_BACKTRACE environmental variable

Invalid context errors happen, because you are trying to use drawing operations outside of drawRect: method, so no current graphic context is set.

Like on OS X, you should perform drawing in drawRect: method, and use setNeedsDisplay to update resulting image. And both setNeedsDisplay and setNeedsDisplayInRect: methods are available for UIView on iOS.

So, result should look like this:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches]anyObject];
CGPoint touchLocation = [touch locationInView:self];
myPath = [UIBezierPath bezierPath];
[myPath moveToPoint:touchLocation];
}

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches]anyObject];
CGPoint touchLocation = [touch locationInView:self];
[myPath addLineToPoint:touchLocation];
[self setNeedsDisplay];
}

- (void) drawRect:(CGRect)rect {
[[UIColor blackColor]setStroke];
[[UIColor greenColor]setFill];
[myPath stroke];
}

invalid context 0x0 within custom UIView

In the documentation for the draw(_ rect: CGRect) function. (Last paragraph of the "Discussion".)

You should never call this method directly yourself.

If you want to trigger this function you should use...

self.setNeedsDisplay()

Documentation for the draw function.

However

As @vacawama pointed out (and I missed) the draw function will be called after adding your view to the view hierarchy anyway. So you shouldn't need to call it at all here. It will happen automatically for you.

So inside the init methods, just remove the call altogether.

The place to call it again is if the view changes shape for instance or if you want to change the contents of it. i.e. colour, or something.

CGContextSaveGState: invalid context 0x0 (Xcode 7 GM)

This also happens for me on 7 GM, but removing UIViewControllerBasedStatusBarAppearance from Info.plist fixed it for me, as said here.

Update: Warning seems to be gone with iOS 9.2

Invalid context when drawing bezierPath on CAShapeLayer

dont have to call drawing methods

bezierPath.stroke()

The CAShapeLayer will draw itself in the dentView

and do you really need

UIColor.label.setStroke()

as you have already have set the strokeColor in someFunc()

Here is what worked without error:

class ThirdViewController: UIViewController {
let dentDisplayMultiplier : Float = 6
var shape = CAShapeLayer()

@IBOutlet weak var dentView: UIView!


func someFunc() {
self.dentView.layer.addSublayer(self.shape)

let color: UIColor = .systemGreen
self.shape.fillColor = color.withAlphaComponent(0.3).cgColor
self.shape.strokeColor = color.cgColor
self.shape.lineWidth = 6
self.shape.path = self.bezierPath(dentInMM: 3)
}

func bezierPath(dentInMM value: Float) -> CGPath {
self.shape.frame = self.dentView.bounds

let x000 = Int(self.shape.frame.minX)
let x050 = Int(self.shape.frame.midX)
let x100 = Int(self.shape.frame.maxX)
let x010 = x100 / 10
let x040 = x050 - x010
let x060 = x050 + x010
let yOffSet = Int(self.shape.frame.minY)

let indentation = Int(value * self.dentDisplayMultiplier)

let bezierPath = UIBezierPath()
bezierPath.move(to: CGPoint(x: x000, y: yOffSet))
bezierPath.addCurve(to: CGPoint(x: x050, y: indentation), controlPoint1: CGPoint(x: x050, y: yOffSet), controlPoint2: CGPoint(x: x040, y: indentation))
bezierPath.addCurve(to: CGPoint(x: x100, y: yOffSet), controlPoint1: CGPoint(x: x060, y: indentation), controlPoint2: CGPoint(x: x050, y: yOffSet))

return bezierPath.cgPath
}

override func viewDidLoad() {


super.viewDidLoad()
// Do any additional setup after loading the view.
someFunc()

}

}

CGContextSaveGState: invalid context 0x0 Error only on device

From my experimentation, this seems to be due to defining UIViewControllerBasedStatusBarAppearance in Info.plist.

It happens on iOS 9 (beta & GM) but not on 8.4.



Related Topics



Leave a reply



Submit