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 have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Profiler.BeginSample/EndSample error request

Discussion in 'Editor & General Support' started by dburden1, Jun 30, 2016.

  1. dburden1

    dburden1

    Joined:
    Jan 29, 2015
    Posts:
    19
    In a future release, could the error about non-matching profiler BeginSample and EndSample counts point towards which file/line in which the mismatch is occurring? We just noticed this error sometime in the past few weeks. We're not exactly sure when it started, we don't know where the mismatch is, and the error gives absolutely no information. The entire error is just: "Non matching Profiler.EndSample (BeginSample and EndSample count must match)"

    It wouldn't be a big deal, except that when we get this error, the profiler stops showing any and all data/graphs, effectively making the profiler useless. There's no telling where the mismatch could be; we have a ton of code spread throughout thousands of scripts, many of which make use of the profiler samples. It can take ages to track this sort of thing down. Putting some additional information in this error message would be immensely helpful.
     
  2. alexandre-fiset

    alexandre-fiset

    Joined:
    Mar 19, 2012
    Posts:
    702
    ^this.
    We also have the same error and don't know where the hell it comes from. I'd guess it's from some loading routine as it only happens in between our scenes. I also feel like it's responsible for some of our crashes.
     
  3. Stenkrona

    Stenkrona

    Joined:
    Oct 3, 2015
    Posts:
    2
    I too have this problem.
     
  4. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,511
    I went through the entire scripts and I have never used Profiler feature, yet I have this error popping up from time to time if profiler is open. The profiler still works though. But it is very annoying indeed.
     
  5. ratking

    ratking

    Joined:
    Feb 24, 2010
    Posts:
    348
    Same here. It would be very useful to know, especially as I don't use the Profiler class in my own code.
     
  6. ad4m4

    ad4m4

    Joined:
    Apr 8, 2016
    Posts:
    1
    I disabled the VSync in the Profiler window and this error disappeared
     
    KarlKarl2000 likes this.
  7. atmosgames

    atmosgames

    Joined:
    Dec 14, 2011
    Posts:
    71
    Yep! That works. Just disable vsync. The tiny little square on the left of CPU Usage
     
  8. KateKhinkelIridescent

    KateKhinkelIridescent

    Joined:
    Aug 21, 2020
    Posts:
    9
    Be sure you use it inside main thread! Found here:
    "Cannot may be executed in coroutines or separate threads. Be aware that if you will decide to move your code to a separate thread, you shouldn’t call Unity API from within that thread. Instead you should use components like Dispatcher from UnityToolbag that will dispatch Unity API calls to the main thread."
     
    webbertakken likes this.
  9. Arganoid

    Arganoid

    Joined:
    Oct 12, 2013
    Posts:
    24
    This may be outdated, according to this it should be thread safe as of 2018.2
    https://forum.unity.com/threads/profiling-background-threads.521196/