代码之家  ›  专栏  ›  技术社区  ›  Kristina

为什么这段代码分解CGColor会导致总线错误?

  •  0
  • Kristina  · 技术社区  · 15 年前

    使用此代码会导致总线错误。有人能指出它有什么问题吗?我正在重写CALayer的一个方法。

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

    附笔。 红色:green:blue:alpha是一个工作非常好的类方法 .

    这就是原型:

    + (CGColorRef) colorWithRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha
    
    1 回复  |  直到 15 年前
        1
  •  0
  •   Kristina    15 年前

    *组件 数组小于2,所以我正在访问不存在的成员。