xcode工具查找内存问题,访问另一个变量ecc的位置的指针
|
我正在使用cocos2d,但是问题很普遍。
我有一堂课
CCNode *scaleLayer
我设置的touchesMoved事件
scaleLayer.scale=(some calculation)
如果我在设备上编译,程序会崩溃,在模拟器上效果很好。
如果我将nslogs放在之前的指令之前,即使在设备中也能正常工作。
可能是一些内存,指针还是什么?
但是,存在一个xcode工具,可以使我发现或理解我的眼光在哪里?
谢谢
这是代码:
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *allTouches = [event allTouches];
//NSLog(@\"comincio\");
switch ([allTouches count]) {
case 2: { //Double Touch
UITouch *t1 = [[allTouches allObjects] objectAtIndex:0];
UITouch *t2 = [[allTouches allObjects] objectAtIndex:1];
CGPoint p1=[self convertTouchToNodeSpace: t1];
CGPoint p2=[self convertTouchToNodeSpace: t2];
initialDistance = [self distanceBetweenTwoPoints:p1 B:p2];
oldScale=scaleLayer.scale;
NSLog(@\"distanza iniz %f\",initialDistance);
} break;
default:
break;
}
}
-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
CGPoint location;
UITouch *t1,*t2;
CGPoint p1,p2;
NSSet *allTouces=[event allTouches];
switch ([allTouces count]) {
case 2:
//NSLog(@\"2 tocchi\");
t1=[[allTouces allObjects] objectAtIndex:0];
t2=[[allTouces allObjects] objectAtIndex:1];
p1=[self convertTouchToNodeSpace: t1];
p2=[self convertTouchToNodeSpace: t2];
CGFloat finalDistance=[self distanceBetweenTwoPoints:p1 B:p2];
//if i put here NSLog(\"%f %f %f\",oldScale,finalDistance,initialDistance); all goes well
scaleLayer.scale=oldScale*finalDistance/initialDistance;
NSLog(@\"scala %f\",scaleLayer.scale);//finalDistance/initialDistance);
//this nslog give me error if i not put that nslog before
break;
default:
break;
}
}
-(CGFloat)distanceBetweenTwoPoints:(CGPoint)A B:(CGPoint)B{
float x=B.x-A.x;
float y=B.y-A.y;
return sqrt(x*x+y*y);
}
没有找到相关结果
已邀请:
2 个回复
膝垫富顷
倪蕊悲潍