Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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

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

  1. Aurimas-Cernius


    Unity Technologies

    Jul 31, 2013
    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();
    7.             var vMin = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
    8.             var vMax = new Vector3(float.MinValue, float.MinValue, float.MinValue);
    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.             }
    19.             var bounds = new Bounds(vMin,;
    20.             bounds.Encapsulate(vMax);
    21.             return bounds;
    22.         }