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
  4. Dismiss Notice

Question The case of the mysterious randomly multiplying Game windows

Discussion in 'Editor & General Support' started by FU_JPS, Apr 8, 2022.

  1. FU_JPS

    FU_JPS

    Joined:
    Nov 21, 2012
    Posts:
    12
    Our team frequently encounters a mysterious editor bug in which the Game window multiplies on playback startup, causing instability issues, slowdown, and massive memory consumption, and in severe cases triggering memory allocation errors and causing the whole computer to become unresponsive, requiring a reboot.

    Some details:
    • The Editor is running on Windows 10. The bug manifests in both Unity 2018 (I don't remember the minor version) and 2020.3.11f1.
    • The bug happens infrequently, seemingly at random. There are no errors or warnings in the console when it happens. There's nothing obvious in the editor log.
    • Trying to close one of the Game windows usually kills all of them but leaves a blank gray uncloseable window with a title that says something like "Failed to load window". This uncloseable window will sometimes reappear even after restarting the editor. The only reliable way to fix it is to reset the layout to one of the defaults in the upper-right corner of the editor, but our workflow relies on a lot of custom tool windows and reopening them all is a bit of a productivity sink.

    Some theories as to the cause:

    • Some deep-hidden bug (e.g. race condition?) somewhere in the editor.
    • Some bug in our editor-extending code. This is highly plausible but so far we haven't found anything blatantly obvious. We have lots of custom tool windows, inspectors, asset processor scripts, etc. so it could be anything.
    • Too many custom tool windows are taxing Unity's windowing system to the point of breakage.
    • Too many hidden allocations are causing GC heap fragmentation or pressure which is breaking something somewhere.
    • Project is too big in general. Our project is huge with lots of large FBX files and textures. For reference, the Assets folder is about 100GB and the Library folder is about 800GB on one machine.
    • Some leftover cruft in the Library folder from an earlier state that is causing trouble. (Unfortunately deleting the Library folder and reimporting everything generally takes an entire day. Also, even after a fresh import the bug is known to manifest itself again at random.)
    • Some combination of the above.

    I would like to file a bug report but the size and nature of our content means that the company is extremely hesitant to send the entire project. In addition, I'm not sure whether this is a bug in Unity or in our own custom editor code (either is equally likely).

    That said, is there anyone who has experienced the same problem and might have suggestions?

    Also, would any of the Unity developers be able to point us to what might be causing a new Game window to open? Is there a way we can programmatically detect the issue so we can at least warn the user when it happens?

    Thanks very much to all in advance.

    GameGameGameGameGameGame.png
     
  2. FU_JPS

    FU_JPS

    Joined:
    Nov 21, 2012
    Posts:
    12
    Today I learned you can add multiple Game windows from the right-click "Add Tab" menu. However, we're not adding them intentionally. I suspect there's a use case there for debugging VR...?

    Anyway, for now I added an editor-only check that gets all windows of type
    UnityEditor.GameView
    and warns the user when there are two or more:

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3.  
    4. namespace WindowUtilities
    5. {
    6.     public static class MultipleGameWindowChecker
    7.     {
    8.         public static void WarnIfMultipleGameWindowsFound()
    9.         {
    10.             var type = typeof(EditorWindow).Assembly.GetType("UnityEditor.GameView");
    11.             var windows = Resources.FindObjectsOfTypeAll(type);
    12.             if (windows.Length >= 2)
    13.             {
    14.                 EditorUtility.DisplayDialog(
    15.                     "Multiple Game windows detected!",
    16.                     "Multiple Game windows detected!\nYou may want to close some of them!",
    17.                     "OK");
    18.             }
    19.         }
    20.     }
    21. }
    22.