1

I've been getting a EXC_BAD_ACCESS error while drawing, filling and then stroking a path. Here is the code:

UIBezierPath *aPath = [UIBezierPath bezierPath];

[aPath moveToPoint:CGPointMake(0, 88)];
[aPath addLineToPoint:CGPointMake(interPoint, 0)];
[aPath addLineToPoint:CGPointMake(interPoint, 176)];
[aPath addLineToPoint:CGPointMake(0, 88)];

[aPath closePath];

[[UIColor blackColor] setStroke];
[[UIColor colorWithHue:0.1583 saturation:1 brightness:1 alpha:1.0] setFill];

aPath.lineWidth = 1;

[aPath fill];
[aPath stroke];

The error seems to be happening when the program gets to [aPath stroke]. If I comment out [aPath stroke] the error goes away. I know that an EXC_BAD_ACCESS error has to do with memory management, but I can't figure out where the problem is. Any help would be great.

4

1 回答 1

0

要找出 EXC_BAD_ACCESS 错误的原因和位置,请执行以下步骤:

在 Xcode 中转到Product -> Scheme -> Edit Scheme 会弹出一个屏幕。在那个选择参数选项卡中。在此转到环境变量部分,然后单击添加按钮以添加名称为 NSZombieEnable 且值为 YES 的属性。

现在运行您的应用程序。它将为您提供 EXC_BAD_ACCESS 错误的详细日志。

您可以使用[variableName retain]在内存中释放变量之前增加变量保留计数;

在你的情况下使用[aPath retain]; 在 aPath 被释放之前。

于 2013-07-03T09:45:39.807 回答