0

我必须CGMutablePathRef在返回之前释放它,否则应用程序会崩溃。我应该在哪里发布它?

我在返回之前尝试过,但它仍然崩溃......

+(UIBezierPath*) smoothedBezierOutlinePathWithCGPath:(CGPathRef)path tension:(CGFloat) tension
    {
        CGMutablePathRef smoothedCGPath = CreateSmoothedBezierPathFromPath(path, tension);
        UIBezierPath* smoothedBezierPath = [UIBezierPath bezierPathWithCGPath:smoothedCGPath];
        CGPathRelease(smoothedCGPath);

        return smoothedBezierPath;
    }
CGMutablePathRef CreateSmoothedBezierPathFromPath( CGPathRef path, CGFloat tention)
    {
        //convert path to 2 arrays of CGFloats
        struct dataPointer my_dataPointer; //this struct will hold the 2 indexes of the CGpath
        my_dataPointer.numberOfPoints = 0;
        my_dataPointer.isClosed = NO;
        CGPathApply(path, &my_dataPointer, savePathToArraysApplierFunc);

        //the arrays where the control points will be stored
        CGFloat controlPoints_x[2*_max_points];
        CGFloat controlPoints_y[2*_max_points];

        calculateBezierControlPoints(  controlPoints_x, controlPoints_y, my_dataPointer.indexx , my_dataPointer.indexy, my_dataPointer.isClosed, my_dataPointer.numberOfPoints, tention);

        //the final CGpath constisting of original points and computed control points
        CGMutablePathRef bezierPath = CGPathCreateMutable();
        for (int i = 0; i<my_dataPointer.numberOfPoints + (int) my_dataPointer.isClosed; i++)
        {
            if(i==0)
               CGPathMoveToPoint(bezierPath, nil, my_dataPointer.indexx[0], my_dataPointer.indexy[0]);
            else if (i==my_dataPointer.numberOfPoints) //this happens when the path is closed
                CGPathAddCurveToPoint(bezierPath, nil, controlPoints_x[i*2-2], controlPoints_y[i*2-2], controlPoints_x[i*2-1], controlPoints_y[i*2-1],my_dataPointer.indexx[0], my_dataPointer.indexy[0]);
            else
                CGPathAddCurveToPoint(bezierPath, nil, controlPoints_x[i*2-2], controlPoints_y[i*2-2], controlPoints_x[i*2-1], controlPoints_y[i*2-1],my_dataPointer.indexx[i], my_dataPointer.indexy[i]);
        }
        if(my_dataPointer.isClosed)
            CGPathCloseSubpath(bezierPath);

        //app crashes here before returning.

        return bezierPath;

    }

我想在哪里发布它?我也尝试过在全球范围内发布它,但没有用。请问有人可以帮我吗?

4

0 回答 0