Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color Crashing Ring #11

Closed
Treverr opened this issue Nov 27, 2016 · 7 comments
Closed

Color Crashing Ring #11

Treverr opened this issue Nov 27, 2016 · 7 comments

Comments

@Treverr
Copy link

Treverr commented Nov 27, 2016

Hello,

I have two rings inside of a standard UIViewController, and when I add the second one it says

"MKRingProgressView was compiled with optimization - stepping may behave oddly; variables may not be available."

When the app crashes.

Also, I am getting a error: IB Designables: Failed to render and update auto layout status for HomeViewController (h2x-s1-kZZ): The agent crashed

Any idea what could be causing this?

@Treverr
Copy link
Author

Treverr commented Nov 27, 2016

I just have two different UIViews set as MKRingProgressview that causes the crash. Not inside of one another.

@Treverr
Copy link
Author

Treverr commented Nov 27, 2016

It is crashing on this line:

self.init(r: UInt8((c?[0])! * 0xff), g: UInt8((c?[1])! * 0xff), b: UInt8((c?[2])! * 0xff), a: UInt8((c?[3])! * 0xff))

in the MKGradientGenerator.swift file

@Treverr Treverr changed the title Crashes with two rings Color Crashing Ring Nov 27, 2016
@Treverr
Copy link
Author

Treverr commented Nov 27, 2016

It looks like the Cyan color is crashing the ring actually

@maxkonovalov
Copy link
Owner

Hi @Treverr!
I was able to reproduce your issue by adding a single progress view in storyboard and assigning start/end colors (no matter what values) in View Attributes Inspector. So looks like it has something to do with the @IBInspectable properties. Leaving the "Default" values for these attributes in storyboard and setting the colors in code worked fine though, so I suggest you to use this workaround for now, while I look for a solution to fix this.
If you have any thoughts on this, please let me know.

@purpleblues
Copy link

purpleblues commented Dec 3, 2016

@maxkonovalov

This is due to the wide range of color from iOS10. Each CGColor component can have value bigger than 1.0 or smaller than 0.0.

If you are ok with ignoring the wide range of color, you can use this initializer in extension RGBA in MKGradientGenerator.swift

fileprivate init(_ color: CGColor) {

        let c = color.components?.map({ (v) -> CGFloat in
            if v < 0.0 {
                return 0.0
            }else if v > 1.0 {
                return 1.0
            } else {
                return v
            }
        })

        switch color.numberOfComponents {
        case 2:
            self.init(r: UInt8((c?[0])! * 0xff), g: UInt8((c?[0])! * 0xff), b: UInt8((c?[0])! * 0xff), a: UInt8((c?[1])! * 0xff))
        case 4:
            self.init(r: UInt8((c?[0])! * 0xff), g: UInt8((c?[1])! * 0xff), b: UInt8((c?[2])! * 0xff), a: UInt8((c?[3])! * 0xff))
        default:
            self.init()
        }
    }

@jendaz
Copy link

jendaz commented Feb 2, 2017

@maxkonovalov @purpleblues solution fixes that issue. Could you add it into the code and cocoa pods?

MariusCiocanel pushed a commit to MariusCiocanel/MKRingProgressView that referenced this issue Feb 8, 2017
…omponent values are within the 0.0 -> 1.0 interval

Using @purpleblues’s suggestion maxkonovalov#11 (comment)
maxkonovalov added a commit that referenced this issue Feb 14, 2017
@maxkonovalov
Copy link
Owner

@Treverr @purpleblues @jendaz
Sorry guys for the delay, finally got my hands on the fix – should work without crashes now 🎉
Thanks @MariusCiocanel for the PR 😉

Please note that the current fix may cause some colors to be displayed incorrectly on wide-gamut screens due to clamped values.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants