我得到hexTouchAreas
作为我的方法 -drawHexagonTouchArea
的返回值,但是当我分析我的工程时,它写着CGMutablePathRef hexTouchArea = CGPathCreateMubable ();
产生警告 : “ 在HexTouchArea 初始化过程中保存到它的价值从未读读过 。 ” 在写着 CGPathRelease (hexTouchArea) 的行内, 它抱怨我并不拥有该对象, 释放它也是多余的 。
另一个警告是在线 return path;
上,分析器说:“在629线上分配并存储到路径的物体(即CGMubablePathRef path = CGPathCreate Mutabable ();
)可能泄漏”
-(void)createTouchAreas{
int realPositionsCount =[[GameStateSingleton sharedMySingleton]getSharedRealCountOfPositions];
hexTouchAreas = [[GameStateSingleton sharedMySingleton]getSharedHexTouchAreas];
NSMutableDictionary *existingHexagons = [[GameStateSingleton sharedMySingleton]getExistingHexagons];
for (int i = 0; i <= realPositionsCount;i++){
//create touchareas
NSString *hexKey = [NSString stringWithFormat:@"hexagon%d", i];
CCSprite *theSprite = [[existingHexagons objectForKey:hexKey]objectForKey:@"realSprite"];
CGPoint touchAreaOrigin = ccp(theSprite.position.x -22, theSprite.position.y-40);
NSString *touchAreaKey = [NSString stringWithFormat:@"hexTouchArea%d",i];
CGMutablePathRef hexTouchArea = CGPathCreateMutable();
hexTouchArea = (CGMutablePathRef) [self drawHexagonTouchArea:touchAreaOrigin];
[hexTouchAreas setObject:(id)hexTouchArea forKey:touchAreaKey];
[[GameStateSingleton sharedMySingleton]setSharedHexTouchAreas:hexTouchAreas];
CGPathRelease(hexTouchArea);
}
}
创建和返回路径的方法 :
-(CGMutablePathRef)drawHexagonTouchArea:(CGPoint)origin
{
CGMutablePathRef path = CGPathCreateMutable();
CGPoint newloc = CGPointMake(origin.x, origin.y);
CGPathMoveToPoint(path, NULL, newloc.x, newloc.y);
CGPathAddLineToPoint(path, NULL, newloc.x -22,newloc.y + 38);
CGPathAddLineToPoint(path, NULL, newloc.x + 0, newloc.y + 76);
CGPathAddLineToPoint(path, NULL, newloc.x + 46, newloc.y + 76);
CGPathAddLineToPoint(path, NULL, newloc.x +66,newloc.y + 40);
CGPathAddLineToPoint(path, NULL, newloc.x +44, newloc.y + 0);
CGPathCloseSubpath(path);
return path;
}