Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice
  4. Join us on Thursday, September 29, for a day with Unity's SRP teams here on the forum or on Reddit, and discuss topics around URP, HDRP, and the Scriptable Render Pipeline in general.
    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

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,276
    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.         }
     
unityunity