我正在使用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);
}
答案 0 :(得分:0)
尝试使用静态分析器构建(Shift-Command-A)
尝试观看内存地址。以下是一些可以帮助您入门的链接: scottmpeak.com和SO discussion
答案 1 :(得分:0)