Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Editor hangs with Profiling Progress - Parsing Profiler Data: 0/xxxkb processed

Discussion in '2020.1 Beta' started by Guedez, Jul 10, 2020.

  1. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    826
    As in the picture:

    Since it's not a crash, I have no idea how to send any kind of related stack trace
    Happens in 2020.1.0b14
    Could be related to "Profiler: Fixed profiler collecting samples when Playmode is paused (1244286)" fixed in b15

    Update: Still happens in b15
     
    Last edited: Jul 10, 2020
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,571
    If you have a project where you're able to reproduce this issue, please submit a bug-report as described in this document:
    https://unity3d.com/unity/qa/bug-reporting

    It's important that you report these issues together with a reproduction project if you want them to get fixed. If you don't do it, it might be a long time until someone else reports them or until Unity Technologies find them.

    After you submitted the bug-report, you receive a confirmation email with a bug-report Case number. Please post the Case number (number only, not the link) in this forum thread for Unity staff to pick up.
     
    alexeyzakharov and Guedez like this.
  3. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    826
    Bug Report Number: 1̶2̶6̶2̶8̶7̶8 1262892, the bug report needed to be uploaded twice due to connection failure. I can only hope the second one actually went with the files.
     
    Last edited: Jul 15, 2020
    alexeyzakharov and Peter77 like this.
  4. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    826
    And I think I found the issue.
    The player was also crashing when attempting to close it. I attached the debugger and got this here:
    The code gets stuck at Library\PackageCache\com.unity.ui@1.0.0-preview.3\Core\Renderer\UIRenderer\UIRenderDevice.cs line 1057
    I had not made the connection yet, but the issue did start quickly after updating my UI Toolkit to the new
    "com.unity.ui": "1.0.0-preview.3"
    package.
    Could be something else, but this seems very suspicious
    Code (CSharp):
    1. private static void ProcessDeviceFreeQueue()
    2.         {
    3.             s_MarkerFree.Begin();
    4.  
    5.             if (m_SynchronousFree)
    6.                 Utility.SyncRenderThread(); <<this line
    7.  
    8.             var freeNode = m_DeviceFreeQueue.First;
    9.             while (freeNode != null)
    10.             {
    11.                 if (!Utility.CPUFencePassed(freeNode.Value.handle))
    12.                     break;
    13.                 freeNode.Value.Dispose();
    14.                 m_DeviceFreeQueue.RemoveFirst();
    15.                 freeNode = m_DeviceFreeQueue.First;
    16.             }
    17.  
    18.             // After synchronizing with the render thread, all cpu fences should pass.
    19.             Debug.Assert(!m_SynchronousFree || m_DeviceFreeQueue.Count == 0);
    20.  
    21.             if (m_ActiveDeviceCount == 0 && m_SubscribedToNotifications)
    22.             {
    23.                 if (s_WhiteTexel != null)
    24.                 {
    25.                     UIRUtility.Destroy(s_WhiteTexel);
    26.                     s_WhiteTexel = null;
    27.                 }
    28.                 if (s_DefaultShaderInfoTexFloat != null)
    29.                 {
    30.                     UIRUtility.Destroy(s_DefaultShaderInfoTexFloat);
    31.                     s_DefaultShaderInfoTexFloat = null;
    32.                 }
    33.                 if (s_DefaultShaderInfoTexARGB8 != null)
    34.                 {
    35.                     UIRUtility.Destroy(s_DefaultShaderInfoTexARGB8);
    36.                     s_DefaultShaderInfoTexARGB8 = null;
    37.                 }
    38.                 Utility.NotifyOfUIREvents(false);
    39.                 m_SubscribedToNotifications = false;
    40.             }
    41.  
    42.             s_MarkerFree.End();
    43.         }
     
  5. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    826
    Another update, I caught unity hanging again and this time the debugger managed to get me some info. one of the threads was hanging here at
    PackageCache\com.unity.ui@1.0.0-preview.3\Core\IMGUIContainer.cs:333

    Hopefully it's relevant. Pressing F5 never steps into nor F6 steps over. It is permanently stuck there. Since I seem to be the only person with this issue, I wonder if it is not hanging while attempting to draw some custom window or inspector I made. The issue is that I don't really know how to get any info out of
    onGUIHandler
    . This is what the VS Inspector has to say about it:

    Most relevant piece of code:
    Code (CSharp):
    1.             try
    2.             {
    3.                 using (new GUIClip.ParentClipScope(parentTransform, clippingRect))
    4.                 {
    5.                     onGUIHandler(); <<< This line
    6.                     #if DEBUG_IMGUI_CONTAINER_EVENTS
    7.                     Console.WriteLine($"{s_OnGUICounter++} {this.GetDisplayName()}.OnGUI({evt.rawType}>{Event.current.type})");
    8.                     #endif
    9.                 }
    10.             }
    11.             catch (Exception exception)
    12.             {
    13.                 // only for layout events: we always intercept any exceptions to not interrupt event processing
    14.                 if (originalEventType == EventType.Layout)
    15.                 {
    16.                     isExitGUIException = GUIUtility.IsExitGUIException(exception);
    17.                     if (!isExitGUIException)
    18.                     {
    19.                         Debug.LogException(exception);
    20.                     }
    21.                 }
    22.                 else
    23.                 {
    24.                     // rethrow event if not in layout
    25.                     throw;
    26.                 }
    27.             }
    28.             finally
    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3.  
    4. namespace UnityEngine.UIElements
    5. {
    6.     /// <summary>
    7.     /// Element that draws IMGUI content.
    8.     /// </summary>
    9.     public class IMGUIContainer : VisualElement, IDisposable
    10.     {
    11.         /// <summary>
    12.         /// Instantiates an <see cref="IMGUIContainer"/> using the data read from a UXML file.
    13.         /// </summary>
    14.         public new class UxmlFactory : UxmlFactory<IMGUIContainer, UxmlTraits> {}
    15.  
    16.         /// <summary>
    17.         /// Defines <see cref="UxmlTraits"/> for the <see cref="IMGUIContainer"/>.
    18.         /// </summary>
    19.         public new class UxmlTraits : VisualElement.UxmlTraits
    20.         {
    21.             /// <summary>
    22.             /// Constructor.
    23.             /// </summary>
    24.             public UxmlTraits()
    25.             {
    26.                 focusIndex.defaultValue = 0;
    27.                 focusable.defaultValue = true;
    28.             }
    29.  
    30.             /// <summary>
    31.             /// Returns an empty enumerable, as IMGUIContainer cannot have VisualElement children.
    32.             /// </summary>
    33.             public override IEnumerable<UxmlChildElementDescription> uxmlChildElementsDescription
    34.             {
    35.                 get { yield break; }
    36.             }
    37.         }
    38.  
    39.         // Set this delegate to have your IMGUI code execute inside the container
    40.         private Action m_OnGUIHandler;
    41.         /// <summary>
    42.         /// The function that is called to render and handle IMGUI events.
    43.         /// </summary>
    44.         /// <remarks>
    45.         /// The function is assigned to onGUIHandler and is similar to <see cref="MonoBehaviour.OnGUI"/>.
    46.         /// </remarks>
    47.         public Action onGUIHandler
    48.         {
    49.             get { return m_OnGUIHandler; }
    50.             set
    51.             {
    52.                 if (m_OnGUIHandler != value)
    53.                 {
    54.                     m_OnGUIHandler = value;
    55.                     IncrementVersion(VersionChangeType.Layout);
    56.                     IncrementVersion(VersionChangeType.Repaint);
    57.                 }
    58.             }
    59.         }
    60.  
    61.         // If needed, an IMGUIContainer will allocate native state via this utility object to store control IDs
    62.         ObjectGUIState m_ObjectGUIState;
    63.  
    64.         internal ObjectGUIState guiState
    65.         {
    66.             get
    67.             {
    68.                 Debug.Assert(!useOwnerObjectGUIState);
    69.                 if (m_ObjectGUIState == null)
    70.                 {
    71.                     m_ObjectGUIState = new ObjectGUIState();
    72.                 }
    73.                 return m_ObjectGUIState;
    74.             }
    75.         }
    76.  
    77.         // This is not nice but needed until we properly remove the dependency on GUIView's own ObjectGUIState
    78.         // At least this implementation is not needed for users, only for containers created to wrap each GUIView
    79.         internal bool useOwnerObjectGUIState;
    80.         internal Rect lastWorldClip { get; set; }
    81.  
    82.         // If true, skip OnGUI() calls when outside the viewport
    83.         private bool m_CullingEnabled = false;
    84.         // If true, the IMGUIContainer received Focus through delgation
    85.         private bool m_IsFocusDelegated = false;
    86.         /// <summary>
    87.         /// When this property is set to true, <see cref="onGUIHandler"/> is not called when the Element is outside the viewport.
    88.         /// </summary>
    89.         public bool cullingEnabled
    90.         {
    91.             get { return m_CullingEnabled; }
    92.             set { m_CullingEnabled = value; IncrementVersion(VersionChangeType.Repaint); }
    93.         }
    94.  
    95.         private bool m_RefreshCachedLayout = true;
    96.         private GUILayoutUtility.LayoutCache m_Cache = null;
    97.         private GUILayoutUtility.LayoutCache cache
    98.         {
    99.             get
    100.             {
    101.                 if (m_Cache == null)
    102.                     m_Cache = new GUILayoutUtility.LayoutCache();
    103.                 return m_Cache;
    104.             }
    105.         }
    106.  
    107.         // We cache the clipping rect and transform during regular painting so that we can reuse them
    108.         // during the DoMeasure call to DoOnGUI(). It's still important to not
    109.         // pass Rect.zero for the clipping rect as this eventually sets the
    110.         // global GUIClip.visibleRect which IMGUI code could be using to influence
    111.         // size. See case 1111923 and 1158089.
    112.         private Rect m_CachedClippingRect = Rect.zero;
    113.         private Matrix4x4 m_CachedTransform = Matrix4x4.identity;
    114.  
    115.         private float layoutMeasuredWidth
    116.         {
    117.             get
    118.             {
    119.                 return Mathf.Ceil(cache.topLevel.maxWidth);
    120.             }
    121.         }
    122.  
    123.         private float layoutMeasuredHeight
    124.         {
    125.             get
    126.             {
    127.                 return Mathf.Ceil(cache.topLevel.maxHeight);
    128.             }
    129.         }
    130.  
    131.         /// <summary>
    132.         /// ContextType of this IMGUIContrainer. Currently only supports ContextType.Editor.
    133.         /// </summary>
    134.         public ContextType contextType { get; set; }
    135.  
    136.         // The following 2 flags indicate the following :
    137.         // 1) lostFocus : a blur event occurred and we need to make sure the actual keyboard focus from IMGUI is really un-focused
    138.         bool lostFocus = false;
    139.         // 2) receivedFocus : a Focus event occurred and we need to focus the actual IMGUIContainer as being THE element focused.
    140.         bool receivedFocus = false;
    141.         FocusChangeDirection focusChangeDirection = FocusChangeDirection.unspecified;
    142.         bool hasFocusableControls = false;
    143.  
    144.         int newKeyboardFocusControlID = 0;
    145.  
    146.         internal bool focusOnlyIfHasFocusableControls { get; set; } = true;
    147.  
    148.         public override bool canGrabFocus => focusOnlyIfHasFocusableControls ? hasFocusableControls && base.canGrabFocus : base.canGrabFocus;
    149.  
    150.         /// <summary>
    151.         /// USS class name of elements of this type.
    152.         /// </summary>
    153.         public static readonly string ussClassName = "unity-imgui-container";
    154.  
    155.         /// <summary>
    156.         /// Constructor.
    157.         /// </summary>
    158.         public IMGUIContainer()
    159.             : this(null)
    160.         {
    161.         }
    162.  
    163.         /// <summary>
    164.         /// Constructor.
    165.         /// </summary>
    166.         /// <param name="onGUIHandler">The function assigned to <see cref="onGUIHandler"/>.</param>
    167.         public IMGUIContainer(Action onGUIHandler)
    168.         {
    169.             isIMGUIContainer = true;
    170.  
    171.             AddToClassList(ussClassName);
    172.  
    173.             this.onGUIHandler = onGUIHandler;
    174.             contextType = ContextType.Editor;
    175.             focusable = true;
    176.  
    177.             requireMeasureFunction = true;
    178.             generateVisualContent += OnGenerateVisualContent;
    179.         }
    180.  
    181.         private void OnGenerateVisualContent(MeshGenerationContext mgc)
    182.         {
    183.             lastWorldClip = elementPanel.repaintData.currentWorldClip;
    184.  
    185.             // Access to the painter is internal and is not exposed to public
    186.             // The IStylePainter is kept as an interface rather than a concrete class for now to support tests
    187.             mgc.painter.DrawImmediate(DoIMGUIRepaint, cullingEnabled);
    188.         }
    189.  
    190.         // global GUI values.
    191.         // container saves and restores them before doing his thing
    192.         private struct GUIGlobals
    193.         {
    194.             public Matrix4x4 matrix;
    195.             public Color color;
    196.             public Color contentColor;
    197.             public Color backgroundColor;
    198.             public bool enabled;
    199.             public bool changed;
    200.             public int displayIndex;
    201.         }
    202.  
    203.         private GUIGlobals m_GUIGlobals;
    204.  
    205.         private void SaveGlobals()
    206.         {
    207.             m_GUIGlobals.matrix = GUI.matrix;
    208.             m_GUIGlobals.color = GUI.color;
    209.             m_GUIGlobals.contentColor = GUI.contentColor;
    210.             m_GUIGlobals.backgroundColor = GUI.backgroundColor;
    211.             m_GUIGlobals.enabled = GUI.enabled;
    212.             m_GUIGlobals.changed = GUI.changed;
    213.             if (Event.current != null)
    214.             {
    215.                 m_GUIGlobals.displayIndex = Event.current.displayIndex;
    216.             }
    217.         }
    218.  
    219.         private void RestoreGlobals()
    220.         {
    221.             GUI.matrix = m_GUIGlobals.matrix;
    222.             GUI.color = m_GUIGlobals.color;
    223.             GUI.contentColor = m_GUIGlobals.contentColor;
    224.             GUI.backgroundColor = m_GUIGlobals.backgroundColor;
    225.             GUI.enabled = m_GUIGlobals.enabled;
    226.             GUI.changed = m_GUIGlobals.changed;
    227.             if (Event.current != null)
    228.             {
    229.                 Event.current.displayIndex = m_GUIGlobals.displayIndex;
    230.             }
    231.         }
    232.  
    233.         #if DEBUG_IMGUI_CONTAINER_EVENTS
    234.         static int s_OnGUICounter = 1;
    235.         #endif
    236.         private void DoOnGUI(Event evt, Matrix4x4 parentTransform, Rect clippingRect, bool isComputingLayout, Rect layoutSize, Action onGUIHandler, bool canAffectFocus = true)
    237.         {
    238.             // Extra checks are needed here because client code might have changed the IMGUIContainer
    239.             // since we enter HandleIMGUIEvent()
    240.             if (onGUIHandler == null
    241.                 || panel == null)
    242.             {
    243.                 return;
    244.             }
    245.  
    246.             // Save the GUIClip count to make sanity checks after calling the OnGUI handler
    247.             int guiClipCount = GUIClip.Internal_GetCount();
    248.  
    249.             SaveGlobals();
    250.  
    251.             // Save a copy of the container size.
    252.             var previousMeasuredWidth = layoutMeasuredWidth;
    253.             var previousMeasuredHeight = layoutMeasuredHeight;
    254.  
    255.             UIElementsUtility.BeginContainerGUI(cache, evt, this);
    256.  
    257.             // For the IMGUI, we need to update the GUI.color with the actual play mode tint ...
    258.             // In fact, this is taken from EditorGUIUtility.ResetGUIState().
    259.             // Here, the play mode tint is either white (no tint, or not in play mode) or the right color (if in play mode)
    260.             GUI.color = UIElementsUtility.editorPlayModeTintColor;
    261.             // From now on, Event.current is either evt or a copy of evt.
    262.             // Since Event.current may change while being processed, we do not rely on evt below but use Event.current instead.
    263.  
    264.             if (Event.current.type != EventType.Layout)
    265.             {
    266.                 if (lostFocus)
    267.                 {
    268.                     if (focusController != null)
    269.                     {
    270.                         // We dont want to clear the GUIUtility.keyboardControl if another IMGUIContainer
    271.                         // just set it in the if (receivedFocus) block below. So we only clear it if own it.
    272.                         if (GUIUtility.OwnsId(GUIUtility.keyboardControl))
    273.                         {
    274.                             GUIUtility.keyboardControl = 0;
    275.                             focusController.imguiKeyboardControl = 0;
    276.                         }
    277.                     }
    278.                     lostFocus = false;
    279.                 }
    280.  
    281.                 if (receivedFocus)
    282.                 {
    283.                     if (hasFocusableControls)
    284.                     {
    285.                         if (focusChangeDirection != FocusChangeDirection.unspecified && focusChangeDirection != FocusChangeDirection.none)
    286.                         {
    287.                             // We got here by tabbing.
    288.  
    289.                             // We assume we are using the VisualElementFocusRing.
    290.                             if (focusChangeDirection == VisualElementFocusChangeDirection.left)
    291.                             {
    292.                                 GUIUtility.SetKeyboardControlToLastControlId();
    293.                             }
    294.                             else if (focusChangeDirection == VisualElementFocusChangeDirection.right)
    295.                             {
    296.                                 GUIUtility.SetKeyboardControlToFirstControlId();
    297.                             }
    298.                         }
    299.                         else if (GUIUtility.keyboardControl == 0 && m_IsFocusDelegated)
    300.                         {
    301.                             // Since GUIUtility.keyboardControl == 0, we got focused in some other way than by clicking inside us
    302.                             // (for example it could be by clicking in an element that delegates focus to us).
    303.                             // Give GUIUtility.keyboardControl to our first control.
    304.                             GUIUtility.SetKeyboardControlToFirstControlId();
    305.                         }
    306.                     }
    307.  
    308.                     if (focusController != null)
    309.                     {
    310.                         if (focusController.imguiKeyboardControl != GUIUtility.keyboardControl && focusChangeDirection != FocusChangeDirection.unspecified)
    311.                         {
    312.                             newKeyboardFocusControlID = GUIUtility.keyboardControl;
    313.                         }
    314.  
    315.                         focusController.imguiKeyboardControl = GUIUtility.keyboardControl;
    316.                     }
    317.  
    318.                     receivedFocus = false;
    319.                     focusChangeDirection = FocusChangeDirection.unspecified;
    320.                 }
    321.                 // We intentionally don't send the NewKeyboardFocus command here since it creates an issue with the AutomatedWindow
    322.                 // newKeyboardFocusControlID = GUIUtility.keyboardControl;
    323.             }
    324.  
    325.             EventType originalEventType = Event.current.type;
    326.  
    327.             bool isExitGUIException = false;
    328.  
    329.             try
    330.             {
    331.                 using (new GUIClip.ParentClipScope(parentTransform, clippingRect))
    332.                 {
    333.                     onGUIHandler();
    334.                     #if DEBUG_IMGUI_CONTAINER_EVENTS
    335.                     Console.WriteLine($"{s_OnGUICounter++} {this.GetDisplayName()}.OnGUI({evt.rawType}>{Event.current.type})");
    336.                     #endif
    337.                 }
    338.             }
    339.             catch (Exception exception)
    340.             {
    341.                 // only for layout events: we always intercept any exceptions to not interrupt event processing
    342.                 if (originalEventType == EventType.Layout)
    343.                 {
    344.                     isExitGUIException = GUIUtility.IsExitGUIException(exception);
    345.                     if (!isExitGUIException)
    346.                     {
    347.                         Debug.LogException(exception);
    348.                     }
    349.                 }
    350.                 else
    351.                 {
    352.                     // rethrow event if not in layout
    353.                     throw;
    354.                 }
    355.             }
    356.             finally
    357.             {
    358.                 if (Event.current.type != EventType.Layout && canAffectFocus)
    359.                 {
    360.                     int currentKeyboardFocus = GUIUtility.keyboardControl;
    361.                     int result = GUIUtility.CheckForTabEvent(Event.current);
    362.                     if (focusController != null)
    363.                     {
    364.                         if (result < 0)
    365.                         {
    366.                             // If CheckForTabEvent returns -1 or -2, we have reach the end/beginning of its control list.
    367.                             // We should switch the focus to the next VisualElement.
    368.                             Focusable currentFocusedElement = focusController.GetLeafFocusedElement();
    369.                             Focusable nextFocusedElement = null;
    370.                             using (KeyDownEvent e = KeyDownEvent.GetPooled('\t', KeyCode.Tab, result == -1 ? EventModifiers.None : EventModifiers.Shift))
    371.                             {
    372.                                 nextFocusedElement = focusController.SwitchFocusOnEvent(e);
    373.                             }
    374.  
    375.                             if (currentFocusedElement == this)
    376.                             {
    377.                                 if (nextFocusedElement == this)
    378.                                 {
    379.                                     // We will still have the focus. We should cycle around our controls.
    380.                                     if (result == -2)
    381.                                     {
    382.                                         GUIUtility.SetKeyboardControlToLastControlId();
    383.                                     }
    384.                                     else if (result == -1)
    385.                                     {
    386.                                         GUIUtility.SetKeyboardControlToFirstControlId();
    387.                                     }
    388.  
    389.                                     newKeyboardFocusControlID = GUIUtility.keyboardControl;
    390.                                     focusController.imguiKeyboardControl = GUIUtility.keyboardControl;
    391.                                 }
    392.                                 else
    393.                                 {
    394.                                     // We will lose the focus. Set the focused element ID to 0 until next
    395.                                     // IMGUIContainer have a chance to set it to its own control.
    396.                                     // Doing this will ensure we draw ourselves without any focused control.
    397.                                     GUIUtility.keyboardControl = 0;
    398.                                     focusController.imguiKeyboardControl = 0;
    399.                                 }
    400.                             }
    401.                         }
    402.                         else if (result > 0)
    403.                         {
    404.                             // A positive result indicates that the focused control has changed to one of our elements; result holds the control id.
    405.                             focusController.imguiKeyboardControl = GUIUtility.keyboardControl;
    406.                             newKeyboardFocusControlID = GUIUtility.keyboardControl;
    407.                         }
    408.                         else if (result == 0)
    409.                         {
    410.                             // This means the event is not a tab. Synchronize our focus info with IMGUI.
    411.  
    412.                             if (originalEventType == EventType.MouseDown && !focusOnlyIfHasFocusableControls)
    413.                             {
    414.                                 focusController.SyncIMGUIFocus(GUIUtility.keyboardControl, this, true);
    415.                             }
    416.                             else if ((currentKeyboardFocus != GUIUtility.keyboardControl) || (originalEventType == EventType.MouseDown))
    417.                             {
    418.                                 focusController.SyncIMGUIFocus(GUIUtility.keyboardControl, this, false);
    419.                             }
    420.                             else if (GUIUtility.keyboardControl != focusController.imguiKeyboardControl)
    421.                             {
    422.                                 // Here we want to resynchronize our internal state ...
    423.                                 newKeyboardFocusControlID = GUIUtility.keyboardControl;
    424.  
    425.                                 if (focusController.GetLeafFocusedElement() == this)
    426.                                 {
    427.                                     // In this case, the focused element is the right one in the Focus Controller... we are just updating the internal imguiKeyboardControl
    428.                                     focusController.imguiKeyboardControl = GUIUtility.keyboardControl;
    429.                                 }
    430.                                 else
    431.                                 {
    432.                                     // In this case, the focused element is NOT the right one in the Focus Controller... we also have to refocus...
    433.                                     focusController.SyncIMGUIFocus(GUIUtility.keyboardControl, this, false);
    434.                                 }
    435.                             }
    436.                         }
    437.                     }
    438.                     // Cache the fact that we have focusable controls or not.
    439.                     hasFocusableControls = GUIUtility.HasFocusableControls();
    440.                 }
    441.             }
    442.  
    443.             // This will copy Event.current into evt.
    444.             UIElementsUtility.EndContainerGUI(evt, layoutSize);
    445.             RestoreGlobals();
    446.  
    447.             // See if the container size has changed. This is to make absolutely sure the VisualElement resizes
    448.             // if the IMGUI content resizes.
    449.             if (evt.type == EventType.Layout &&
    450.                 (!Mathf.Approximately(previousMeasuredWidth, layoutMeasuredWidth) || !Mathf.Approximately(previousMeasuredHeight, layoutMeasuredHeight)))
    451.             {
    452.                 if (isComputingLayout)
    453.                     this.schedule.Execute(() => IncrementVersion(VersionChangeType.Layout));
    454.                 else
    455.                     IncrementVersion(VersionChangeType.Layout);
    456.             }
    457.  
    458.             if (!isExitGUIException)
    459.             {
    460.                 // This is the same logic as GUIClipState::EndOnGUI
    461.                 if (evt.type != EventType.Ignore && evt.type != EventType.Used)
    462.                 {
    463.                     int currentCount = GUIClip.Internal_GetCount();
    464.                     if (currentCount > guiClipCount)
    465.                         Debug.LogError("GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced.");
    466.                     else if (currentCount < guiClipCount)
    467.                         Debug.LogError("GUI Error: You are popping more GUIClips than you are pushing. Make sure they are balanced.");
    468.                 }
    469.             }
    470.  
    471.             // Clear extraneous GUIClips
    472.             while (GUIClip.Internal_GetCount() > guiClipCount)
    473.                 GUIClip.Internal_Pop();
    474.  
    475.             if (evt.type == EventType.Used)
    476.             {
    477.                 IncrementVersion(VersionChangeType.Repaint);
    478.             }
    479.         }
    480.  
    481.         /// <summary>
    482.         /// Marks layout as dirty to trigger a redraw.
    483.         /// </summary>
    484.         public void MarkDirtyLayout()
    485.         {
    486.             m_RefreshCachedLayout = true;
    487.             IncrementVersion(VersionChangeType.Layout);
    488.         }
    489.  
    490.         public override void HandleEvent(EventBase evt)
    491.         {
    492.             base.HandleEvent(evt);
    493.  
    494.             if (evt == null)
    495.             {
    496.                 return;
    497.             }
    498.  
    499.             if (evt.propagationPhase != PropagationPhase.TrickleDown &&
    500.                 evt.propagationPhase != PropagationPhase.AtTarget &&
    501.                 evt.propagationPhase != PropagationPhase.BubbleUp)
    502.             {
    503.                 return;
    504.             }
    505.  
    506.             if (evt.imguiEvent == null)
    507.             {
    508.                 return;
    509.             }
    510.  
    511.             if (evt.isPropagationStopped)
    512.             {
    513.                 return;
    514.             }
    515.  
    516.             if (SendEventToIMGUI(evt))
    517.             {
    518.                 evt.StopPropagation();
    519.                 evt.PreventDefault();
    520.             }
    521.         }
    522.  
    523.         // This is the IStylePainterInternal.DrawImmediate callback
    524.         private void DoIMGUIRepaint()
    525.         {
    526.             var offset = elementPanel.repaintData.currentOffset;
    527.             m_CachedClippingRect = ComputeAAAlignedBound(worldClip, offset);
    528.             m_CachedTransform = offset * worldTransform;
    529.  
    530.             HandleIMGUIEvent(elementPanel.repaintData.repaintEvent, m_CachedTransform, m_CachedClippingRect, onGUIHandler, true);
    531.         }
    532.  
    533.         internal bool SendEventToIMGUI(EventBase evt, bool canAffectFocus = true, bool verifyBounds = true)
    534.         {
    535.             if (evt is IPointerEvent)
    536.             {
    537.                 if (evt.imguiEvent != null && evt.imguiEvent.isDirectManipulationDevice)
    538.                 {
    539.                     bool sendPointerEvent = false;
    540.                     EventType originalEventType = evt.imguiEvent.rawType;
    541.                     if (evt is PointerDownEvent)
    542.                     {
    543.                         sendPointerEvent = true;
    544.                         evt.imguiEvent.type = EventType.TouchDown;
    545.                     }
    546.                     else if (evt is PointerUpEvent)
    547.                     {
    548.                         sendPointerEvent = true;
    549.                         evt.imguiEvent.type = EventType.TouchUp;
    550.                     }
    551.                     else if (evt is PointerMoveEvent && evt.imguiEvent.rawType == EventType.MouseDrag)
    552.                     {
    553.                         sendPointerEvent = true;
    554.                         evt.imguiEvent.type = EventType.TouchMove;
    555.                     }
    556.                     else if (evt is PointerLeaveEvent)
    557.                     {
    558.                         sendPointerEvent = true;
    559.                         evt.imguiEvent.type = EventType.TouchLeave;
    560.                     }
    561.                     else if (evt is PointerEnterEvent)
    562.                     {
    563.                         sendPointerEvent = true;
    564.                         evt.imguiEvent.type = EventType.TouchEnter;
    565.                     }
    566.                     else if (evt is PointerStationaryEvent)
    567.                     {
    568.                         sendPointerEvent = true;
    569.                         evt.imguiEvent.type = EventType.TouchStationary;
    570.                     }
    571.  
    572.                     if (sendPointerEvent)
    573.                     {
    574.                         bool result = SendEventToIMGUIRaw(evt, canAffectFocus, verifyBounds);
    575.                         evt.imguiEvent.type = originalEventType;
    576.                         return result;
    577.                     }
    578.                 }
    579.                 // If not touch then we should not handle PointerEvents on IMGUI, we will handle the MouseEvent sent right after
    580.                 return false;
    581.             }
    582.  
    583.             return SendEventToIMGUIRaw(evt, canAffectFocus, verifyBounds);
    584.         }
    585.  
    586.         private bool SendEventToIMGUIRaw(EventBase evt, bool canAffectFocus, bool verifyBounds)
    587.         {
    588.             if (verifyBounds && !VerifyBounds(evt))
    589.                 return false;
    590.  
    591.             bool result;
    592.             using (new EventDebuggerLogIMGUICall(evt))
    593.             {
    594.                 result = HandleIMGUIEvent(evt.imguiEvent, canAffectFocus);
    595.             }
    596.             return result;
    597.         }
    598.  
    599.         private bool VerifyBounds(EventBase evt)
    600.         {
    601.             return IsContainerCapturingTheMouse() || !IsLocalEvent(evt) || IsEventInsideLocalWindow(evt);
    602.         }
    603.  
    604.         private bool IsContainerCapturingTheMouse()
    605.         {
    606.             return this == panel?.dispatcher?.pointerState.GetCapturingElement(PointerId.mousePointerId);
    607.         }
    608.  
    609.         private bool IsLocalEvent(EventBase evt)
    610.         {
    611.             long evtType = evt.eventTypeId;
    612.             return evtType == MouseDownEvent.TypeId() || evtType == MouseUpEvent.TypeId() ||
    613.                 evtType == MouseMoveEvent.TypeId() ||
    614.                 evtType == PointerDownEvent.TypeId() || evtType == PointerUpEvent.TypeId() ||
    615.                 evtType == PointerMoveEvent.TypeId();
    616.         }
    617.  
    618.         private bool IsEventInsideLocalWindow(EventBase evt)
    619.         {
    620.             Rect clippingRect = GetCurrentClipRect();
    621.             string pointerType = (evt as IPointerEvent)?.pointerType;
    622.             bool isDirectManipulationDevice = (pointerType == PointerType.touch || pointerType == PointerType.pen);
    623.             return GUIUtility.HitTest(clippingRect, evt.originalMousePosition, isDirectManipulationDevice);
    624.         }
    625.  
    626.         private bool HandleIMGUIEvent(Event e, bool canAffectFocus)
    627.         {
    628.             return HandleIMGUIEvent(e, onGUIHandler, canAffectFocus);
    629.         }
    630.  
    631.         internal bool HandleIMGUIEvent(Event e, Action onGUIHandler, bool canAffectFocus)
    632.         {
    633.             GetCurrentTransformAndClip(this, e, out m_CachedTransform, out m_CachedClippingRect);
    634.  
    635.             return HandleIMGUIEvent(e, m_CachedTransform, m_CachedClippingRect, onGUIHandler, canAffectFocus);
    636.         }
    637.  
    638.         private bool HandleIMGUIEvent(Event e, Matrix4x4 worldTransform, Rect clippingRect, Action onGUIHandler, bool canAffectFocus)
    639.         {
    640.             if (e == null || onGUIHandler == null || elementPanel == null || elementPanel.IMGUIEventInterests.WantsEvent(e.rawType) == false)
    641.             {
    642.                 return false;
    643.             }
    644.  
    645.             EventType originalEventType = e.rawType;
    646.             if (originalEventType != EventType.Layout)
    647.             {
    648.                 if (m_RefreshCachedLayout || elementPanel.IMGUIEventInterests.WantsLayoutPass(e.rawType))
    649.                 {
    650.                     // Only update the layout in-between repaint events.
    651.                     e.type = EventType.Layout;
    652.                     DoOnGUI(e, worldTransform, clippingRect, false, layout, onGUIHandler, canAffectFocus);
    653.                     m_RefreshCachedLayout = false;
    654.                     e.type = originalEventType;
    655.                 }
    656.                 else
    657.                 {
    658.                     // Reuse layout cache for other events.
    659.                     cache.ResetCursor();
    660.                 }
    661.             }
    662.  
    663.             DoOnGUI(e, worldTransform, clippingRect, false, layout, onGUIHandler, canAffectFocus);
    664.  
    665.             if (newKeyboardFocusControlID > 0)
    666.             {
    667.                 newKeyboardFocusControlID = 0;
    668.                 Event focusCommand = new Event
    669.                 {
    670.                     type = EventType.ExecuteCommand,
    671.                     commandName = EventCommandNames.NewKeyboardFocus
    672.                 };
    673.  
    674.                 HandleIMGUIEvent(focusCommand, true);
    675.             }
    676.  
    677.             if (e.rawType == EventType.Used)
    678.             {
    679.                 return true;
    680.             }
    681.             else if (e.rawType == EventType.MouseUp && this.HasMouseCapture())
    682.             {
    683.                 // This can happen if a MouseDown was caught by a different IM element but we ended up here on the
    684.                 // MouseUp event because no other element consumed it, including the one that had capture.
    685.                 // Example case: start text selection in a text field, but drag mouse all the way into another
    686.                 // part of the editor, release the mouse button.  Since the mouse up was sent to another container,
    687.                 // we end up here and that is perfectly legal (unfortunately unavoidable for now since no IMGUI control
    688.                 // used the event), but hot control might still belong to the IM text field at this point.
    689.                 // We can safely release the hot control which will release the capture as the same time.
    690.                 GUIUtility.hotControl = 0;
    691.             }
    692.  
    693.             // If we detect that we were removed while processing this event, hi-jack the event loop to early exit
    694.             // In IMGUI/Editor this is actually possible just by calling EditorWindow.Close() for example
    695.             if (elementPanel == null)
    696.             {
    697.                 GUIUtility.ExitGUI();
    698.             }
    699.  
    700.             return false;
    701.         }
    702.  
    703.         protected override void ExecuteDefaultAction(EventBase evt)
    704.         {
    705.             if (evt == null)
    706.             {
    707.                 return;
    708.             }
    709.  
    710.             // no call to base.ExecuteDefaultAction(evt):
    711.             // - we dont want mouse click to directly give focus to IMGUIContainer:
    712.             //   they should be handled by IMGUI and if an IMGUI control grabs the
    713.             //   keyboard, the IMGUIContainer will gain focus via FocusController.SyncIMGUIFocus.
    714.             // - same thing for tabs: IMGUI should handle them.
    715.             // - we dont want to set the PseudoState.Focus flag on IMGUIContainer.
    716.             //   They are focusable, but only for the purpose of focusing their children.
    717.  
    718.             // Here, we set flags that will be acted upon in DoOnGUI(), since we need to change IMGUI state.
    719.             if (evt.eventTypeId == BlurEvent.TypeId())
    720.             {
    721.                 // A lost focus event is ... a lost focus event.
    722.                 // The specific handling of the IMGUI will be done in the DoOnGUI() above...
    723.                 lostFocus = true;
    724.  
    725.                 // On lost focus, we need to repaint to remove any focused element blue borders.
    726.                 IncrementVersion(VersionChangeType.Repaint);
    727.             }
    728.             else if (evt.eventTypeId == FocusEvent.TypeId())
    729.             {
    730.                 FocusEvent fe = evt as FocusEvent;
    731.                 receivedFocus = true;
    732.                 focusChangeDirection = fe.direction;
    733.                 m_IsFocusDelegated = fe.IsFocusDelegated;
    734.             }
    735.             else if (evt.eventTypeId == DetachFromPanelEvent.TypeId())
    736.             {
    737.                 if (elementPanel != null)
    738.                 {
    739.                     elementPanel.IMGUIContainersCount--;
    740.                 }
    741.             }
    742.             else if (evt.eventTypeId == AttachToPanelEvent.TypeId())
    743.             {
    744.                 if (elementPanel != null)
    745.                 {
    746.                     elementPanel.IMGUIContainersCount++;
    747.                 }
    748.             }
    749.         }
    750.  
    751.         protected internal override Vector2 DoMeasure(float desiredWidth, MeasureMode widthMode, float desiredHeight, MeasureMode heightMode)
    752.         {
    753.             float measuredWidth = float.NaN;
    754.             float measuredHeight = float.NaN;
    755.  
    756.             if (widthMode != MeasureMode.Exactly || heightMode != MeasureMode.Exactly)
    757.             {
    758.                 var evt = new Event { type = EventType.Layout };
    759.                 var layoutRect = layout;
    760.                 // Make sure the right width/height will be used at the final stage of the calculation
    761.                 switch (widthMode)
    762.                 {
    763.                     case MeasureMode.Exactly:
    764.                         layoutRect.width = desiredWidth;
    765.                         break;
    766.                 }
    767.                 switch (heightMode)
    768.                 {
    769.                     case MeasureMode.Exactly:
    770.                         layoutRect.height = desiredHeight;
    771.                         break;
    772.                 }
    773.                 // When computing layout it's important to not call GetCurrentTransformAndClip
    774.                 // because it will remove the dirty flag on the container transform which might
    775.                 // set the transform in an invalid state. That's why we have to pass
    776.                 // cached transform and clipping state here. It's still important to not
    777.                 // pass Rect.zero for the clipping rect as this eventually sets the
    778.                 // global GUIClip.visibleRect which IMGUI code could be using to influence
    779.                 // size. See case 1111923 and 1158089.
    780.                 DoOnGUI(evt, m_CachedTransform, m_CachedClippingRect, true, layoutRect, onGUIHandler, true);
    781.                 measuredWidth = layoutMeasuredWidth;
    782.                 measuredHeight = layoutMeasuredHeight;
    783.             }
    784.  
    785.             switch (widthMode)
    786.             {
    787.                 case MeasureMode.Exactly:
    788.                     measuredWidth = desiredWidth;
    789.                     break;
    790.                 case MeasureMode.AtMost:
    791.                     measuredWidth = Mathf.Min(measuredWidth, desiredWidth);
    792.                     break;
    793.             }
    794.  
    795.             switch (heightMode)
    796.             {
    797.                 case MeasureMode.Exactly:
    798.                     measuredHeight = desiredHeight;
    799.                     break;
    800.                 case MeasureMode.AtMost:
    801.                     measuredHeight = Mathf.Min(measuredHeight, desiredHeight);
    802.                     break;
    803.             }
    804.  
    805.             return new Vector2(measuredWidth, measuredHeight);
    806.         }
    807.  
    808.         private Rect GetCurrentClipRect()
    809.         {
    810.             Rect clipRect = this.lastWorldClip;
    811.             if (clipRect.width == 0.0f || clipRect.height == 0.0f)
    812.             {
    813.                 // lastWorldClip will be empty until the first repaint occurred,
    814.                 // we fall back on the worldBound in this case.
    815.                 clipRect = this.worldBound;
    816.             }
    817.             return clipRect;
    818.         }
    819.  
    820.         private static void GetCurrentTransformAndClip(IMGUIContainer container, Event evt, out Matrix4x4 transform, out Rect clipRect)
    821.         {
    822.             clipRect = container.GetCurrentClipRect();
    823.  
    824.             transform = container.worldTransform;
    825.             if (evt.rawType == EventType.Repaint
    826.                 && container.elementPanel != null)
    827.             {
    828.                 // during repaint, we must use in case the current transform is not relative to Panel
    829.                 // this is to account for the pixel caching feature
    830.                 transform =  container.elementPanel.repaintData.currentOffset * container.worldTransform;
    831.             }
    832.         }
    833.  
    834.         public void Dispose()
    835.         {
    836.             Dispose(true);
    837.             GC.SuppressFinalize(this);
    838.         }
    839.  
    840.         protected virtual void Dispose(bool disposeManaged)
    841.         {
    842.             if (disposeManaged)
    843.             {
    844.                 m_ObjectGUIState?.Dispose();
    845.             }
    846.         }
    847.     }
    848. }
    849.  
     
  6. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    826
    Managed to detect and fix the issue. This was caused by a bunch of (at least 60000 but I didn't count)
    NativeArrays 
    were being allocated with
    TempJob 
    and failing to deallocate fast enough. I changed them all to Persistent and the issue stopped happening.
     
  7. vignesh211

    vignesh211

    Joined:
    Feb 8, 2019
    Posts:
    13
    @Guedez Can you say how to do that. Iam currently having this issues
     
  8. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    826
    It was an issue specific to my code, try checking every place you allocate native containers to see if there is something doing it excessively.
     
    vignesh211 likes this.