gpt4 book ai didi

iphone - xcode 工具查找内存问题,访问指向另一个变量 ecc 位置的指针

转载 作者:行者123 更新时间:2023-11-28 17:46:28 25 4
gpt4 key购买 nike

我正在使用 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);
}

最佳答案

尝试使用静态分析器 (Shift-Command-A) 构建

尝试观察内存地址。以下是一些帮助您入门的链接: scottmpeak.comSO discussion

关于iphone - xcode 工具查找内存问题,访问指向另一个变量 ecc 位置的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5716241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com