简体   繁体   English

线程1:EXC_BAD_ACCESS代码= 1浮点数*

[英]Thread 1:EXC_BAD_ACCESS code = 1 float *

I know that there are a tons of question with same question, but no one helped me. 我知道有很多问题要问相同的问题,但是没有人帮助过我。

I have Object DimensionItemHolder and property : 我有Object DimensionItemHolder和property:

@property(nonatomic) float *  sum;

in recursion function I have : 在递归函数中,我有:

DimensionItemHolder * holder = [self getDimensionItemWhitIndex:[dimensionItem.dimItemID shortValue]];

if (holder)
{

    NSLog(@"%f , %f , %f , %f , %f  : %p", holder.sum[0],holder.sum[1],holder.sum[2],holder.sum[3],holder.sum[4] , holder.sum);

    [self.itemOrderdArray removeObject:holder];
    [self substractSum:holder.sum];
    NSLog(@"%p", holder.sum);
    return holder.sum;
}

And after few iteration xcode throw 并在几次迭代后将xcode抛出

Thread 1: EXC_BAD_ACCESS(code = 1, address 0xc080000c) 

at line 在线

NSLog(@"%p", holder.sum);

I figer it out that it has to do whit function 我认为它必须具有白色功能

[self substractSum:holder.sum];

(if I comment it it works) (如果我发表评论,它将奏效)

the function is : 功能是:

-(void)substractSum:(float *)subSum{
if (subSum) {
    self.sum[0] = self.sum[0] - subSum[0];
    self.sum[1] = self.sum[1] - subSum[1];
    self.sum[2] = self.sum[2] - subSum[2];
    self.sum[3] = self.sum[3] - subSum[3];
    self.sum[4] = self.sum[4] - subSum[4];
}

} }

I guess you're using float * to enjoy C pointer characteristics and do sum[i] . 我猜您正在使用float *来享受C指针的特性并执行sum[i] But here you are in objectiveC, use NSArray filled with floats. 但是在这里,您在ObjectiveC中,使用充满浮点数的NSArray。

I finally figure it out. 我终于明白了。

It was stupid thing. 这是愚蠢的事情。 I malloc memory for 4 floats and I ask him for holder[4] which is 5 element. 我为4个浮点数分配内存,然后问他5个元素的holder [4]。

Thanks all for help 谢谢大家的帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM