Deep profiling causes "Non matching Profiler.EndSample"

I was deep profiling EnterPlaymode in an empty Unity 2019.3.0f1 project, where the editor spits out the following errors:

Non matching Profiler.EndSample (BeginSample and EndSample count must match): UnityEngine.IMGUIModule.dll!UnityEngine::GUIUtility.ExitGUI()
Previous 5 samples:
    GC.Alloc
    UnityEditor.dll!UnityEditor::SceneVisibilityState.GeneratePersistentDataForAllLoadedScenes()
    Mono.JIT
    GC.Alloc
    UnityEditor.dll!::AssetStoreClientInternal.IsAnyDownloadInProgress()
In the scope:
    UIElementsUtility.DoDispatch(Non Repaint Event)
    UnityEngine.IMGUIModule.dll!UnityEngine::GUIUtility.ProcessEvent()
    EditorLoop
    Main Thread
Non matching Profiler.EndSample (BeginSample and EndSample count must match): UnityEditor.dll!UnityEditor::Toolbar.DoPlayButtons()
Previous 5 samples:
    GC.Alloc
    UnityEditor.dll!UnityEditor::SceneVisibilityState.GeneratePersistentDataForAllLoadedScenes()
    Mono.JIT
    GC.Alloc
    UnityEditor.dll!::AssetStoreClientInternal.IsAnyDownloadInProgress()
In the scope:
    UIElementsUtility.DoDispatch(Non Repaint Event)
    UnityEngine.IMGUIModule.dll!UnityEngine::GUIUtility.ProcessEvent()
    EditorLoop
    Main Thread
Non matching Profiler.EndSample (BeginSample and EndSample count must match): UnityEditor.dll!UnityEditor::Toolbar.OldOnGUI()
Previous 5 samples:
    GC.Alloc
    UnityEditor.dll!UnityEditor::SceneVisibilityState.GeneratePersistentDataForAllLoadedScenes()
    Mono.JIT
    GC.Alloc
    UnityEditor.dll!::AssetStoreClientInternal.IsAnyDownloadInProgress()
In the scope:
    UIElementsUtility.DoDispatch(Non Repaint Event)
    UnityEngine.IMGUIModule.dll!UnityEngine::GUIUtility.ProcessEvent()
    EditorLoop
    Main Thread
Non matching Profiler.EndSample (BeginSample and EndSample count must match): UnityEngine.UIElementsModule.dll!UnityEngine.UIElements::IMGUIContainer.DoOnGUI()
Previous 5 samples:
    GC.Alloc
    UnityEditor.dll!UnityEditor::SceneVisibilityState.GeneratePersistentDataForAllLoadedScenes()
    Mono.JIT
    GC.Alloc
    UnityEditor.dll!::AssetStoreClientInternal.IsAnyDownloadInProgress()
In the scope:
    UIElementsUtility.DoDispatch(Non Repaint Event)
    UnityEngine.IMGUIModule.dll!UnityEngine::GUIUtility.ProcessEvent()
    EditorLoop
    Main Thread
Non matching Profiler.EndSample (BeginSample and EndSample count must match): UnityEngine.UIElementsModule.dll!UnityEngine.UIElements::IMGUIContainer.HandleIMGUIEvent()
Previous 5 samples:
    GC.Alloc
    UnityEditor.dll!UnityEditor::SceneVisibilityState.GeneratePersistentDataForAllLoadedScenes()
    Mono.JIT
    GC.Alloc
    UnityEditor.dll!::AssetStoreClientInternal.IsAnyDownloadInProgress()
In the scope:
    UIElementsUtility.DoDispatch(Non Repaint Event)
    UnityEngine.IMGUIModule.dll!UnityEngine::GUIUtility.ProcessEvent()
    EditorLoop
    Main Thread
Non matching Profiler.EndSample (BeginSample and EndSample count must match): UnityEngine.UIElementsModule.dll!UnityEngine.UIElements::IMGUIContainer.HandleIMGUIEvent()
Previous 5 samples:
    GC.Alloc
    UnityEditor.dll!UnityEditor::SceneVisibilityState.GeneratePersistentDataForAllLoadedScenes()
    Mono.JIT
    GC.Alloc
    UnityEditor.dll!::AssetStoreClientInternal.IsAnyDownloadInProgress()
In the scope:
    UIElementsUtility.DoDispatch(Non Repaint Event)
    UnityEngine.IMGUIModule.dll!UnityEngine::GUIUtility.ProcessEvent()
    EditorLoop
    Main Thread
Non matching Profiler.EndSample (BeginSample and EndSample count must match): UnityEngine.UIElementsModule.dll!UnityEngine.UIElements::IMGUIContainer.SendEventToIMGUI()
Previous 5 samples:
    GC.Alloc
    UnityEditor.dll!UnityEditor::SceneVisibilityState.GeneratePersistentDataForAllLoadedScenes()
    Mono.JIT
    GC.Alloc
    UnityEditor.dll!::AssetStoreClientInternal.IsAnyDownloadInProgress()
In the scope:
    UIElementsUtility.DoDispatch(Non Repaint Event)
    UnityEngine.IMGUIModule.dll!UnityEngine::GUIUtility.ProcessEvent()
    EditorLoop
    Main Thread
Non matching Profiler.EndSample (BeginSample and EndSample count must match): UnityEngine.UIElementsModule.dll!UnityEngine.UIElements::IMGUIContainer.HandleEvent()
Previous 5 samples:
    GC.Alloc
    UnityEditor.dll!UnityEditor::SceneVisibilityState.GeneratePersistentDataForAllLoadedScenes()
    Mono.JIT
    GC.Alloc
    UnityEditor.dll!::AssetStoreClientInternal.IsAnyDownloadInProgress()
In the scope:
    UIElementsUtility.DoDispatch(Non Repaint Event)
    UnityEngine.IMGUIModule.dll!UnityEngine::GUIUtility.ProcessEvent()
    EditorLoop
    Main Thread
Non matching Profiler.EndSample (BeginSample and EndSample count must match): UnityEngine.UIElementsModule.dll!UnityEngine.UIElements::CallbackEventHandler.HandleEventAtTargetPhase()
Previous 5 samples:
    GC.Alloc
    UnityEditor.dll!UnityEditor::SceneVisibilityState.GeneratePersistentDataForAllLoadedScenes()
    Mono.JIT
    GC.Alloc
    UnityEditor.dll!::AssetStoreClientInternal.IsAnyDownloadInProgress()
In the scope:
    UIElementsUtility.DoDispatch(Non Repaint Event)
    UnityEngine.IMGUIModule.dll!UnityEngine::GUIUtility.ProcessEvent()
    EditorLoop
    Main Thread
Non matching Profiler.EndSample (BeginSample and EndSample count must match): UnityEngine.UIElementsModule.dll!UnityEngine.UIElements::MouseCaptureDispatchingStrategy.DispatchEvent()
Previous 5 samples:
    GC.Alloc
    UnityEditor.dll!UnityEditor::SceneVisibilityState.GeneratePersistentDataForAllLoadedScenes()
    Mono.JIT
    GC.Alloc
    UnityEditor.dll!::AssetStoreClientInternal.IsAnyDownloadInProgress()
In the scope:
    UIElementsUtility.DoDispatch(Non Repaint Event)
    UnityEngine.IMGUIModule.dll!UnityEngine::GUIUtility.ProcessEvent()
    EditorLoop
    Main Thread
Non matching Profiler.EndSample (BeginSample and EndSample count must match): UnityEngine.UIElementsModule.dll!UnityEngine.UIElements::EventDispatcher.ProcessEvent()
Previous 5 samples:
    GC.Alloc
    UnityEditor.dll!UnityEditor::SceneVisibilityState.GeneratePersistentDataForAllLoadedScenes()
    Mono.JIT
    GC.Alloc
    UnityEditor.dll!::AssetStoreClientInternal.IsAnyDownloadInProgress()
In the scope:
    UIElementsUtility.DoDispatch(Non Repaint Event)
    UnityEngine.IMGUIModule.dll!UnityEngine::GUIUtility.ProcessEvent()
    EditorLoop
    Main Thread
Non matching Profiler.EndSample (BeginSample and EndSample count must match): UnityEngine.UIElementsModule.dll!UnityEngine.UIElements::EventDispatcher.ProcessEventQueue()
Previous 5 samples:
    GC.Alloc
    UnityEditor.dll!UnityEditor::SceneVisibilityState.GeneratePersistentDataForAllLoadedScenes()
    Mono.JIT
    GC.Alloc
    UnityEditor.dll!::AssetStoreClientInternal.IsAnyDownloadInProgress()
In the scope:
    UIElementsUtility.DoDispatch(Non Repaint Event)
    UnityEngine.IMGUIModule.dll!UnityEngine::GUIUtility.ProcessEvent()
    EditorLoop
    Main Thread
Non matching Profiler.EndSample (BeginSample and EndSample count must match): UnityEngine.UIElementsModule.dll!UnityEngine.UIElements::EventDispatcher.OpenGate()
Previous 5 samples:
    GC.Alloc
    UnityEditor.dll!UnityEditor::SceneVisibilityState.GeneratePersistentDataForAllLoadedScenes()
    Mono.JIT
    GC.Alloc
    UnityEditor.dll!::AssetStoreClientInternal.IsAnyDownloadInProgress()
In the scope:
    UIElementsUtility.DoDispatch(Non Repaint Event)
    UnityEngine.IMGUIModule.dll!UnityEngine::GUIUtility.ProcessEvent()
    EditorLoop
    Main Thread
Non matching Profiler.EndSample (BeginSample and EndSample count must match): UnityEngine.UIElementsModule.dll!UnityEngine.UIElements::EventDispatcherGate.Dispose()
Previous 5 samples:
    GC.Alloc
    UnityEditor.dll!UnityEditor::SceneVisibilityState.GeneratePersistentDataForAllLoadedScenes()
    Mono.JIT
    GC.Alloc
    UnityEditor.dll!::AssetStoreClientInternal.IsAnyDownloadInProgress()
In the scope:
    UIElementsUtility.DoDispatch(Non Repaint Event)
    UnityEngine.IMGUIModule.dll!UnityEngine::GUIUtility.ProcessEvent()
    EditorLoop
    Main Thread
Non matching Profiler.EndSample (BeginSample and EndSample count must match): UnityEngine.UIElementsModule.dll!UnityEngine.UIElements::EventDispatcher.ProcessEvent()
Previous 5 samples:
    GC.Alloc
    UnityEditor.dll!UnityEditor::SceneVisibilityState.GeneratePersistentDataForAllLoadedScenes()
    Mono.JIT
    GC.Alloc
    UnityEditor.dll!::AssetStoreClientInternal.IsAnyDownloadInProgress()
In the scope:
    UIElementsUtility.DoDispatch(Non Repaint Event)
    UnityEngine.IMGUIModule.dll!UnityEngine::GUIUtility.ProcessEvent()
    EditorLoop
    Main Thread
Non matching Profiler.EndSample (BeginSample and EndSample count must match): UnityEngine.UIElementsModule.dll!UnityEngine.UIElements::EventDispatcher.Dispatch()
Previous 5 samples:
    GC.Alloc
    UnityEditor.dll!UnityEditor::SceneVisibilityState.GeneratePersistentDataForAllLoadedScenes()
    Mono.JIT
    GC.Alloc
    UnityEditor.dll!::AssetStoreClientInternal.IsAnyDownloadInProgress()
In the scope:
    UIElementsUtility.DoDispatch(Non Repaint Event)
    UnityEngine.IMGUIModule.dll!UnityEngine::GUIUtility.ProcessEvent()
    EditorLoop
    Main Thread
Non matching Profiler.EndSample (BeginSample and EndSample count must match): UnityEngine.UIElementsModule.dll!UnityEngine.UIElements::BaseVisualElementPanel.SendEvent()
Previous 5 samples:
    GC.Alloc
    UnityEditor.dll!UnityEditor::SceneVisibilityState.GeneratePersistentDataForAllLoadedScenes()
    Mono.JIT
    GC.Alloc
    UnityEditor.dll!::AssetStoreClientInternal.IsAnyDownloadInProgress()
In the scope:
    UIElementsUtility.DoDispatch(Non Repaint Event)
    UnityEngine.IMGUIModule.dll!UnityEngine::GUIUtility.ProcessEvent()
    EditorLoop
    Main Thread
Non matching Profiler.EndSample (BeginSample and EndSample count must match): UnityEngine.UIElementsModule.dll!UnityEngine.UIElements::UIElementsUtility.DoDispatch()
Previous 5 samples:
    GC.Alloc
    UnityEditor.dll!UnityEditor::SceneVisibilityState.GeneratePersistentDataForAllLoadedScenes()
    Mono.JIT
    GC.Alloc
    UnityEditor.dll!::AssetStoreClientInternal.IsAnyDownloadInProgress()
In the scope:
    UnityEngine.IMGUIModule.dll!UnityEngine::GUIUtility.ProcessEvent()
    EditorLoop
    Main Thread
Non matching Profiler.EndSample (BeginSample and EndSample count must match): UnityEngine.UIElementsModule.dll!UnityEngine.UIElements::UIElementsUtility.ProcessEvent()
Previous 5 samples:
    GC.Alloc
    UnityEditor.dll!UnityEditor::SceneVisibilityState.GeneratePersistentDataForAllLoadedScenes()
    Mono.JIT
    GC.Alloc
    UnityEditor.dll!::AssetStoreClientInternal.IsAnyDownloadInProgress()
In the scope:
    UnityEngine.IMGUIModule.dll!UnityEngine::GUIUtility.ProcessEvent()
    EditorLoop
    Main Thread
Non matching Profiler.EndSample (BeginSample and EndSample count must match): UnityEngine.IMGUIModule.dll!UnityEngine::GUIUtility.ProcessEvent()
Previous 5 samples:
    GC.Alloc
    UnityEditor.dll!UnityEditor::SceneVisibilityState.GeneratePersistentDataForAllLoadedScenes()
    Mono.JIT
    GC.Alloc
    UnityEditor.dll!::AssetStoreClientInternal.IsAnyDownloadInProgress()
In the scope:
    EditorLoop
    Main Thread

Reproduce

  • Create new 3D project
  • Open Profiler
  • Enable “Editor” and “Deep Profile”
  • Press Start

Actual
Observe Unity outputs several “Non matching Profiler.EndSample” errors.

2 Likes

Hi Peter,
Thank you for reporting the issue!
I happen to fix very similar issue recently Unity Issue Tracker - Missing Profiler.EndSample error when profiling the Editor and switching between the Profiler window and the Scene View which was related to mismatching begin/end due to exception being thrown in the UI (GUIUtility.ExitGUI() throws an exception).
Although, the fix landed quite a while ago (2019.3b3) and supposedly should not be present in 2019.3.0f1.
There is potentially some other unfixed issue, however, I can’t reproduce it with the latest 2019.3.0f3 and repro steps you described.

To clarify

Create new 3D project
did you mean the default 3D template when creating a new project?

2 Likes

In Unity HUB the tile is just labled “3D”, that’s the project I used to create.

1 Like

Thanks - I’ve created a bug on your behalf for the verification.

1 Like

Hello Peter,

Thank you for taking the time to report this incident, and I hope you are having a good day. My name is Dovydas, and I will be helping you.

Sadly I wasn’t able to reproduce the incident. Does the issue reproduce with other project templates? Are you using a custom Editor layout or the default one?

Any and all information would be greatly appreciated!
If you have any questions, feel free to ask.

Sincerely,
Dovydas Dainys
Customer QA Team

3 Likes

Hello Dovydas,

thank you for the reply.

I’ve tried to reproduce the issue, but it does not reproduce anymore. I’ll keep an eye open.

2 Likes