Search Unity

Warning about VS2015 optimizer bug. Please update to VS2015 Update 1!

Discussion in 'Windows' started by Aurimas-Cernius, Jan 7, 2016.

  1. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    2,223
    TL;DR: the bug has been fixed in Visual Studio 2015 Update 1. Earlier version affected only x64 platform in Mastaer build (.NET Native + Optimize code). Changing to x86 ir disabling code optimization would fix the bug on older VS as well.

    The optimizer bug affected Unity's ScrollView UI component, though it could affect other things as well. The actual issue was that the for loop in bellow code was optimized out entirely, resulting in incorrect calculation results. Be aware, if you have something similar in your code.

    Code (CSharp):
    1. private readonly Vector3[] m_Corners = new Vector3[4];
    2.         private Bounds GetBounds()
    3.         {
    4.             if (m_Content == null)
    5.                 return new Bounds();
    6.  
    7.             var vMin = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
    8.             var vMax = new Vector3(float.MinValue, float.MinValue, float.MinValue);
    9.  
    10.             var toLocal = viewRect.worldToLocalMatrix;
    11.             m_Content.GetWorldCorners(m_Corners);
    12.             for (int j = 0; j < 4; j++)
    13.             {
    14.                 Vector3 v = toLocal.MultiplyPoint3x4(m_Corners[j]);
    15.                 vMin = Vector3.Min(v, vMin);
    16.                 vMax = Vector3.Max(v, vMax);
    17.             }
    18.  
    19.             var bounds = new Bounds(vMin, Vector3.zero);
    20.             bounds.Encapsulate(vMax);
    21.             return bounds;
    22.         }