Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto layout internal error happening when a view is dismissed

I'm getting a funny error when I dismiss some views on which I have some constraints.

Auto layout internal error. Cannot find an outgoing row head for incoming head AppName.ViewName:0x7fc072ed8ef0.Width{id: 6805} during optimization of variable with near-zero coefficient, which should never happen.

I'm getting this bug on several views to which I'm adding these constraints. One variation of this error message is the following:

Auto layout internal error. Cannot find an outgoing row head for incoming head {id: 6630} during optimization of variable with near-zero coefficient, which should never happen.

Has anyone experienced similar issues with this error? Any tips on how to debug it?

like image 285
Unome Avatar asked Dec 22 '15 06:12

Unome


1 Answers

I'm still not 100% sure why this is the way it is, but the key is that you get near-zero coefficient on constraints if you have whole numbers as the constraint values for equal width or height.

For example you can't do flat values like 1.2, or 0.8, you need to do 0.79999 or 1.199999 or you will have crashes on some devices.

I updated all my constraints to use numbers like 0.7999 and it worked.

Want proof of the craziness? Put this in a playground:

let a: Double = 0.8
let b: Double = 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1
print(a == b)

The playground results then read astoundingly:

0.8 0.79999999 "false"

Craziness, but this shows exactly why the bug was happening. Hope this helps.

like image 80
Unome Avatar answered Oct 09 '22 03:10

Unome