我正在尝试沿路径动态绘制曲线以表示山脉。
我有一个返回 a 的函数CGPathRef
,它是一个指向结构的 C 指针。
-(CGPathRef)newPath
{
CGMutablePathRef mutablePath = CGPathCreateMutable();
//inserting quad curves, etc
return mutablePath;
}
然后我CGPathRefs
通过将它们包装在一个UIBezierPath
.
-(NSArray*)otherFunction
{
CGPathRef ref = [self newPath];
UIBezierPath *path = [UIBezierPath bezierPathWithCGPath: ref];
NSArray* paths = @[path];
CGPathRelease(ref);
return paths;
}
然后我获取返回的路径数组并使用SKShapeNode
.
SKShapeNode *node = [SKShapeNode new];
NSArray* paths = [self otherFunction];
CGPathRef ref = [[paths firstObject] CGPath];
node.path = ref;
node.fillColor = [UIColor orangeColor];
node.lineWidth = 2;
最后。
[self addChild:node];
CGPathRelease(node.path);
在我重复这个动作序列几次后,我的程序中断并显示给我。
带有 EXC_BAD_ACCESS 代码 = 2 的 UIApplicationMain。
我知道有内存泄漏。
CGPathRef
我的问题是,当我最终将它传递给几个函数并将它包装在另一个类中时,我该如何处理?
我更新了代码,现在收到 EXC_I386_GPFLT 错误。