Search Unity

JSON Parse error and GarbageCollector diposal of GraphicsBuffer error

Discussion in 'Editor & General Support' started by EpicMcDude, Aug 22, 2021.

  1. EpicMcDude

    EpicMcDude

    Joined:
    Apr 15, 2013
    Posts:
    117
    Hi all,

    I've been having these 2 errors since the beginning of my project, and now I wanted to ask for help because I'm not sure how to fix them as I lack the proper experience to do so!

    This error (warning)
    is actually creating a GPU memory leak which is crashing my PC/Unity Editor after a various tests of the game or if I have it on Play mode for a bit. Also happens when I make a build of the game, the computer will crash after around 20 minutes playing it which is causing problems everyone testing my game.

    I do not know what disposing of GraphicsBuffer entails, or how/where I would use GraphicsBuffer.Release or Dispose(). I am using this PS1 Shader from the asset store, which I suspect this problem is originating from but the creator of the asset is unresponsive to my emails so I can't get his help.
    If it doesn't come from a Shader, would you guys know where it's coming from?

    This other error
    I also have no idea what to do about it because I can't find the path it gives in the error. can't find this file here "Library/PackageCache/com.unity.settings-manager@1.0.2/Editor/PackageSettingsRepository.cs"

    EDIT: Found the file, but I'm not sure what to do with it:

    Code (CSharp):
    1. using System;
    2. using System.IO;
    3. using UnityEngine;
    4.  
    5. namespace UnityEditor.SettingsManagement
    6. {
    7.     /// <inheritdoc />
    8.     /// <summary>
    9.     /// A settings repository that stores data local to a Unity project.
    10.     /// </summary>
    11.     [Serializable]
    12.     public sealed class PackageSettingsRepository : ISettingsRepository
    13.     {
    14.         const string k_PackageSettingsDirectory = "ProjectSettings/Packages";
    15.         const bool k_PrettyPrintJson = true;
    16.  
    17.         bool m_Initialized;
    18.  
    19.         [SerializeField]
    20.         string m_Name;
    21.  
    22.         [SerializeField]
    23.         string m_Path;
    24.  
    25.         [SerializeField]
    26.         SettingsDictionary m_Dictionary = new SettingsDictionary();
    27.  
    28.         /// <summary>
    29.         /// Constructor sets the serialized data path.
    30.         /// </summary>
    31.         /// <param name="package">
    32.         /// The package name.
    33.         /// </param>
    34.         /// <param name="name">
    35.         /// A name for this settings file. Settings are saved in `ProjectSettings/Packages/{package}/{name}.json`.
    36.         /// </param>
    37.         public PackageSettingsRepository(string package, string name)
    38.         {
    39.             m_Name = name;
    40.             m_Path = GetSettingsPath(package, name);
    41.             m_Initialized = false;
    42.  
    43.             AssemblyReloadEvents.beforeAssemblyReload += Save;
    44.             EditorApplication.quitting += Save;
    45.         }
    46.  
    47.         void Init()
    48.         {
    49.             if (m_Initialized)
    50.                 return;
    51.  
    52.             m_Initialized = true;
    53.  
    54.             if (File.Exists(path))
    55.             {
    56.                 m_Dictionary = null;
    57.                 var json = File.ReadAllText(path);
    58.                 EditorJsonUtility.FromJsonOverwrite(json, this);
    59.                 if(m_Dictionary == null)
    60.                     m_Dictionary = new SettingsDictionary();
    61.             }
    62.         }
    63.  
    64.         /// <value>
    65.         /// This repository implementation is relevant to the Project scope.
    66.         /// </value>
    67.         /// <inheritdoc cref="ISettingsRepository.scope"/>
    68.         public SettingsScope scope
    69.         {
    70.             get { return SettingsScope.Project; }
    71.         }
    72.  
    73.         /// <value>
    74.         /// The full path to the settings file.
    75.         /// This corresponds to `Unity Project/Project Settings/Packages/com.unity.package/name`.
    76.         /// </value>
    77.         /// <inheritdoc cref="ISettingsRepository.path"/>
    78.         public string path
    79.         {
    80.             get { return m_Path; }
    81.         }
    82.  
    83.         /// <summary>
    84.         /// The name of this settings file.
    85.         /// </summary>
    86.         public string name
    87.         {
    88.             get { return m_Name; }
    89.         }
    90.  
    91.         // Cannot call FindFromAssembly from a constructor or field initializer
    92. //        static string CreateSettingsPath(Assembly assembly, string name)
    93. //        {
    94. //            var info = PackageManager.PackageInfo.FindForAssembly(assembly);
    95. //            return string.Format("{0}/{1}/{2}.json", k_PackageSettingsDirectory, info.name, name);
    96. //        }
    97.  
    98.         /// <summary>
    99.         /// Get a path for a settings file relative to the calling assembly package directory.
    100.         /// </summary>
    101.         /// <param name="packageName">The name of the package requesting this setting.</param>
    102.         /// <param name="name">An optional name for the settings file. Default is "Settings."</param>
    103.         /// <returns>A package-scoped path to the settings file within Project Settings.</returns>
    104.         public static string GetSettingsPath(string packageName, string name = "Settings")
    105.         {
    106.             return string.Format("{0}/{1}/{2}.json", k_PackageSettingsDirectory, packageName, name);
    107.         }
    108.  
    109.         /// <summary>
    110.         /// Save all settings to their serialized state.
    111.         /// </summary>
    112.         /// <inheritdoc cref="ISettingsRepository.Save"/>
    113.         public void Save()
    114.         {
    115.             Init();
    116.  
    117.             if (!File.Exists(path))
    118.             {
    119.                 var directory = Path.GetDirectoryName(path);
    120.                 Directory.CreateDirectory(directory);
    121.             }
    122.  
    123. #if UNITY_2019_3_OR_NEWER
    124.             if (!AssetDatabase.IsOpenForEdit(path))
    125.             {
    126.                 if (!AssetDatabase.MakeEditable(path))
    127.                 {
    128.                     Debug.LogWarning($"Could not save package settings to {path}");
    129.                     return;
    130.                 }
    131.             }
    132. #endif
    133.  
    134.             try
    135.             {
    136.                 File.WriteAllText(path, EditorJsonUtility.ToJson(this, k_PrettyPrintJson));
    137.             }
    138.             catch (UnauthorizedAccessException)
    139.             {
    140.                 Debug.LogWarning($"Could not save package settings to {path}");
    141.             }
    142.         }
    143.  
    144.         /// <summary>
    145.         /// Set a value for key of type T.
    146.         /// </summary>
    147.         /// <param name="key">The settings key.</param>
    148.         /// <param name="value">The value to set. Must be serializable.</param>
    149.         /// <typeparam name="T">Type of value.</typeparam>
    150.         /// <inheritdoc cref="ISettingsRepository.Set{T}"/>
    151.         public void Set<T>(string key, T value)
    152.         {
    153.             Init();
    154.             m_Dictionary.Set<T>(key, value);
    155.         }
    156.  
    157.         /// <summary>
    158.         /// Get a value with key of type T, or return the fallback value if no matching key is found.
    159.         /// </summary>
    160.         /// <param name="key">The settings key.</param>
    161.         /// <param name="fallback">If no key with a value of type T is found, this value is returned.</param>
    162.         /// <typeparam name="T">Type of value to search for.</typeparam>
    163.         /// <inheritdoc cref="ISettingsRepository.Get{T}"/>
    164.         public T Get<T>(string key, T fallback = default(T))
    165.         {
    166.             Init();
    167.             return m_Dictionary.Get<T>(key, fallback);
    168.         }
    169.  
    170.         /// <summary>
    171.         /// Does the repository contain a setting with key and type.
    172.         /// </summary>
    173.         /// <param name="key">The settings key.</param>
    174.         /// <typeparam name="T">The type of value to search for.</typeparam>
    175.         /// <returns>True if a setting matching both key and type is found, false if no entry is found.</returns>
    176.         /// <inheritdoc cref="ISettingsRepository.ContainsKey{T}"/>
    177.         public bool ContainsKey<T>(string key)
    178.         {
    179.             Init();
    180.             return m_Dictionary.ContainsKey<T>(key);
    181.         }
    182.  
    183.         /// <summary>
    184.         /// Remove a key value pair from the settings repository.
    185.         /// </summary>
    186.         /// <param name="key"></param>
    187.         /// <typeparam name="T"></typeparam>
    188.         /// <inheritdoc cref="ISettingsRepository.Remove{T}"/>
    189.         public void Remove<T>(string key)
    190.         {
    191.             Init();
    192.             m_Dictionary.Remove<T>(key);
    193.         }
    194.     }
    195. }
    196.  



    But I also suspect this might come from ProBuilder, as I was using it to create some blockouts of the levels, and then switched to UModeler and deleted the ProBuilder asset from the Package Manager.

    But yeah, any help would be greatly appreciated, especially for the memory leak one which is pretty bad!
     
    Last edited: Aug 22, 2021
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    Does this package come in source form? See if there are any direct GraphicsBuffer calls in it.

    Can you put that package into a new project and build it and see the same error?

    In other news, there is another PSX package (Free) that I've used and I don't think it has any problem like this.

    https://github.com/dsoft20/psx_retroshader
     
  3. EpicMcDude

    EpicMcDude

    Joined:
    Apr 15, 2013
    Posts:
    117
    Thank you Kurt, I'm using this shader asset on another project but that project has no memory leaks of any kind or problems with the GraphicsBuffer.
    I tried 3 different PSX shaders (that one included) before settling on this one just because it suits all of my needs with light/shadow support and good vertex remapping.
    For some reason, this project is the only one having this issue. I also just tested deleting this package and the GraphicsBuffer does not show up, so it's definitely coming from this shader.

    Would you know if it's possible to just write a line of code in the shader script, that is for example: on scene unload or destroy, do the GraphicsBuffer.Dispose()?
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    That actually exceeds my knowledge, and lacking the actual problem in front of me, I can't really even test or experiment with Google fixes to see.

    You might actually get some traction over in the graphics group on one of these forums:

    https://forum.unity.com/categories/graphics.75/

    Another strategy would be to experiment with using a higher version of Unity... I would stay in the same year series though.

    WARNING: don't try upgrading Unity versions without making a FULL backup, or having 100% airtight source control!
     
    EpicMcDude likes this.
  5. EpicMcDude

    EpicMcDude

    Joined:
    Apr 15, 2013
    Posts:
    117
    Ah I see, well the problem seems to have went away, for now at least. I believe I had done this before, deleting the asset from my project and re-importing it, but the error cam e back. But in any case, it is gone for now, and if it comes back I will do the same process.

    The only error that is popping up on my console right now it's this damn thing that won't go away no matter what I do:

    I've tried:
    • Deleting the Library folder and letting unity rebuild it
    • Replacing the PackageSettingsRepository.cs script from another project, so that Unity would regenerate it.
    • I created a Settings.json file inside ..\ProjectSettings\Packages\com.unity.settings-manager\ folder because this folder was missing from this project.
    • Added this inside of the JSON file
      Code (JSON):
      1.     {
      2.         "m_Name": "Settings",
      3.         "m_Path": "ProjectSettings/Packages/com.unity.settings-manager/Settings.json",
      4.         "m_Dictionary": {
      5.             "m_DictionaryValues": []
      6.         }
      7.     }
      8.  
      because apparently that worked for some other people in the forum.
    But nothing works so far and that error just keeps popping up over and over. Is it something to worry about? It seems it would affect the settings on the Editor?
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    Hard to predict what it might affect but it certainly seems benign. Seems weird that one project is giving all those weird errors... Have you tried copying the Assets folder out to a brand newly-made empty project and then just quickly put the bundle identifier and name in, whatever the minimum work is, then try and build that new project?

    I have had "cruft" build up in ProjectSettings.asset over time, and this was a way to clear it. For instance half a decade ago I had mobile fog get stuck OFF in a Unity4.6 project, but they removed that control in Unity5+, so I had to hand-monkey-patch the ProjectSettings.asset file, which I only discovered by nuking it and making a fresh project. With source control I could see all the diffs and tracked it down. I wonder if something like that might be going on for you.