Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Jobs menu crashing [Fix]

Discussion in 'Linux' started by JooleanLogic, Dec 15, 2018.

  1. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    I'm on 2018.3.0b12 and simply clicking on the Jobs menu crashes Unity.
    In a previous version like 2018.2.14f, I could open the Jobs menu but it would similarly crash if I actually clicked any of the options so it seems to be an ongoing problem at least on my system. Linux Mint 19.

    In 2018.3.0b12, I just create a new completely blank project, add the Entities package to get the Jobs menu then mouse over it and it crashes.

    Unity throws up the Bug Reporter window on crashing with these Editor logs attached. I assume Editor-prev.log refers to the log from the previous running of Unity? If so, the previous Unity was launched from the actual Editor folder and the current one was launched from the Unity Hub but it crashes either way.

    The current log (launched from hub) doesn't seem to have any errors at all but the previous one is referring to 2.1.4 even though I launched 3.0b12. Not sure why. I don't seem to have any environment variables referring to Unity.

    Editor.log
    Editor-prev.log
     
  2. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    Ok so after restarting Unity over 9000 times, the issue is actually to do with Menu.SetChecked("menu", true) and not jobs or burst themselves.
    SetChecked("item", true) can't be called twice within a menu validation function.

    So if you want to get access to the jobs menu, comment out all the SetChecked calls in BurstMenu.cs and JobsMenu.cs.
    You could perhaps move all those calls to a single menu item like "Update CheckMarks" in order to set them all at once so you can still see what is/isn't checked.

    I just found this post with same issue from a year ago.
     
  3. senkal_

    senkal_

    Joined:
    May 22, 2018
    Posts:
    86
  4. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    Thanks for the update on that bug senkai.
    That particular issue is fixed (though still dodgy) but this new bug is related to the same SetChecked function.
    I say dodgy because the menu disappears after the first time an item is checked and this still happens in my case as well.
    I'd guess that it's the same underlying issue that perhaps hasn't been properly addressed.

    I removed this example below from my previous post once I realised the problem was SetChecked related and found that previous bug post, but it outlines the current incarnation of the problem.
    Essentially you can't called SetChecked twice within the menu validation phase.

    Code (CSharp):
    1. using UnityEditor;
    2.  
    3. static class TestMenu
    4. {
    5.     private const string sItemOne = "Foo/Bar/Item 1";
    6.     private const string sItemTwo = "Foo/Bar/Item 2";
    7.     private const string sCheck = "Foo/Check Bar Items";
    8.     private const string sUncheck = "Foo/Uncheck Bar Items";
    9.  
    10.     private static int _counter = 0;
    11.  
    12.     // Menu Items
    13.     [MenuItem(sItemOne)]
    14.     private static void one() {}
    15.     [MenuItem(sItemTwo)]
    16.     private static void two(){}
    17.  
    18.  
    19.     // Validate Menu Items
    20.     [MenuItem(sItemOne, true)]
    21.     static bool oneb()
    22.     {
    23.         Menu.SetChecked(sItemOne, _counter >= 1);
    24.         return true;
    25.     }
    26.  
    27.     [MenuItem(sItemTwo, true)]
    28.     private static bool twob()
    29.     {
    30.         Menu.SetChecked(sItemTwo, _counter >= 3);
    31.         _counter++;
    32.         return true;
    33.     }
    34.  
    35.  
    36.     [MenuItem(sCheck)]
    37.     private static void check() => checkBarItems(true);
    38.     [MenuItem(sUncheck)]
    39.     private static void uncheck() => checkBarItems(false);
    40.  
    41.     private static void checkBarItems(bool check)
    42.     {
    43.         Menu.SetChecked(sItemOne, check);   // Ok to check two menu items
    44.         Menu.SetChecked(sItemTwo, check);   // from non-validation function
    45.     }
    46. }
    The list numbers below represent each time the Bar submenu is displayed.
    1. Both items are unchecked.
    2. The menu will disappear in response to checking Item 1.
    3. Item one will appear checked
    4. The menu will disappear in response to checking Item 2
    5. Item two will appear checked
    If you subsequently uncheck both via "Uncheck Bar Items", then the next time you mouse over the Bar menu, it will crash because it attempted to check two items at once.
     
  5. senkal_

    senkal_

    Joined:
    May 22, 2018
    Posts:
    86
    Then definitely it is worth to check if it's reported and create a bug if not.
     
  6. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    Ok for anyone with this problem, here's a temporary hack.
    Just add this file into your project wherever.

    JobMenuFix.cs
    Code (CSharp):
    1. using UnityEditor;
    2. using Unity.Collections;            // NativeLeakDetection
    3. using Unity.Jobs.LowLevel.Unsafe;   // JobsUtility
    4.  
    5.  
    6. /// <summary>
    7. /// Fixes the 'Jobs' menu crash
    8. ///
    9. /// Unity crashes if two or more items of the same check-state
    10. /// are flipped within the menu validation phase.
    11. /// We fix this by pre-setting all the checkmarks before the
    12. /// validation phase.
    13. ///
    14. /// Valid for packages
    15. ///     com.unity.burst@0.2.4-preview.37
    16. ///     com.unity.jobs@0.0.7-preview.5
    17. /// </summary>
    18.  
    19. [InitializeOnLoad]
    20. static class JobMenuFix
    21. {
    22.     private static bool _jobsFixed = false;
    23.  
    24.     static JobMenuFix()
    25.     {
    26.         if (_jobsFixed)
    27.             return;
    28.         _jobsFixed = true;
    29.         EditorApplication.update += FixMenu;
    30.     }
    31.  
    32.     private static void FixMenu()
    33.     {
    34.         EditorApplication.update -= FixMenu;
    35.  
    36.         string[] items = {
    37.                 "JobsDebugger",
    38.                 "Leak Detection (Native Containers)",
    39.                 "Use Burst Jobs",
    40.                 "Enable Burst Safety Checks",
    41.                 "Enable Burst Compilation",
    42.                 "Show Burst Timings"};
    43.  
    44.         bool[] values = {
    45.                 JobsUtility.JobDebuggerEnabled,
    46.                 NativeLeakDetection.Mode == NativeLeakDetectionMode.Enabled,
    47.                 JobsUtility.JobCompilerEnabled, // && BurstCompilerServiceIsInitialized <--No access to this
    48.                 EditorPrefs.GetBool("BurstSafetyChecks"),
    49.                 EditorPrefs.GetBool("BurstCompilation"),
    50.                 EditorPrefs.GetBool("BurstShowTimings")};
    51.  
    52.         for( int i=0; i<items.Length; i++)
    53.         {
    54.             Menu.SetChecked($"Jobs/{items[i]}", values[i]);
    55.         }
    56.     }
    57. }
     
  7. snowcave

    snowcave

    Joined:
    Nov 15, 2018
    Posts:
    4
    Appreciate the fix but it still crashes for me. Arch Linux, tried both the latest packages and the ones listed in the comment, Unity 2018.3.1.
     
  8. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    Sorry snowcave. I don't doubt it's still possible to miss some combinations with that script cos if it gets one or two pre-settings wrong, it can still crash.

    If you want to know for sure if it's actually a SetChecked menu problem and not something else, try this.
    In your Unity project, go to your Library/PackageCache folder and within the burst and jobs package sub folders are two files, BurstMenu.cs and JobsMenu.cs. They're each inside the Editor folder of their package folders.
    Open these and comment out every Menu.SetChecked line. These are read-only files so make sure your changes actually saved. Then reopen Unity and if the Jobs menu still crashes, it's likely a different issue altogether and possibly something to do with the BurstCompilerService or JobsUtility.
     
    snowcave likes this.
  9. snowcave

    snowcave

    Joined:
    Nov 15, 2018
    Posts:
    4
    Hmm, yes the problem is definitely the SetChecked. I'll mess around with your fix, thanks.

    ETA: Ah ha! Using Unity 2018.3.1 and the latest packages I needed to add "Burst Inspector" and "EditorPrefs.GetBool("BurstInspector") respectively under "Use Burst Jobs" (and remove "(Native Containers)" from "Leak Detection." Thanks again!

    ETA 2: Scratch that, I accidentally still had some OnCheckedMenus commented out. Ah well, it works well enough for until I can figure it out.
     
    Last edited: Jan 19, 2019
  10. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    Glad to hear.
    Yeah it's quite a pain but at least it's solvable. I literally spent an entire day crashing and restarting Unity to resolve it on mine but it hasn't crashed since.

    The fix script isn't perfect either as the set condition for "Use Burst Jobs" is
    (JobsUtility.JobCompilerEnabled && BurstCompilerServiceIsInitialized)
    but you don't have access to BurstCompilerService in that script. So that could end up with the wrong value.
    Originally I had to comment out all the SetChecked calls and then turn off "Use Burst Jobs" and possibly something else before I could re-enable everything and the script would work. I.e. I had to get the initial conditions right (bit hit and miss) but after that, it's been fine.

    I tried to get on earlier and mention that "Leak Detection" change but the forums have been down for me for hours. Just something you have to check with each new release.
    Anyway, good luck with it and post if you happen to find a more robust solution.