简体   繁体   English

为什么这段破坏CGColor的代码会导致总线错误?

[英]Why does this chunk of code breaking up a CGColor cause a Bus Error?

Using this code causes a Bus Error. 使用此代码会导致总线错误。 Can someone point out what is wrong with it? 有人可以指出这是怎么回事吗? I'm overriding a method from CALayer. 我正在重写CALayer的方法。

- (void) setBackgroundColor:(CGColorRef)c
{
    float *components = (float *)CGColorGetComponents(c);
    [super setBackgroundColor:[LOLColors colorWithRed:components[0] green:components[1] blue:components[2] alpha:transparencyLevel]];
}

PS colorWithRed:green:blue:alpha is a class method which works perfectly fine . PS colorWithRed:green:blue:alpha是一个很好的类方法

That's the prototype: 那是原型:

+ (CGColorRef) colorWithRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha

And again, figured by trial and error. 再一次,是反复试验得出的结论。

The size of *components array was smaller than 2 so I was accessing non-existent members. * components数组的大小小于2,因此我正在访问不存在的成员。

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

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