SO I finally tracked down the problem. This line was the issue:
CGFloat dashArray[] = {5,2};
CGContextSetLineDash(context, 3, dashArray, 4);
I started getting the following error message:
CGContextSetLineDash: invalid dash array: negative lengths are not allowed.
On further investigation, turns out that I needed to fix the parameters that I was sending to CGContextSetLineDash. The following worked:
CGFloat dashArray[] = {5,2};
CGContextSetLineDash(context, 0, dashArray, 2);
The wrong code is working in debug mode though, which is what caused the confusion over what was wrong. Hope this helps someone in the future.