2D Toolkit Forum

2D Toolkit => Support => Topic started by: MBoffin on December 29, 2015, 11:21:32 pm

Title: Unity closes (not crashes) any time I try to commit to a Sprite Collection
Post by: MBoffin on December 29, 2015, 11:21:32 pm
Not sure what is up here, but it's infuriating. I'm using 2D Toolkit 2.5.5 with Unity 5.3.1f1. Here are the steps to reproduce:
Title: Re: Unity closes (not crashes) any time I try to commit to a Sprite Collection
Post by: MBoffin on December 30, 2015, 01:57:01 am
Things I have tried to do to solve this:
Title: Re: Unity closes (not crashes) any time I try to commit to a Sprite Collection
Post by: kenglou.lee on December 30, 2015, 06:13:41 am
I think I found the reason why it crashes, in tk2dUtil.cs, I found that the "SetDirty" functions keep pointing back to itself due to the "UNITY_EDITOR" pragma, I change it to as below and it seems solve my problem. Hope that helps you. I had report this to moderator and hopefully to get a fix ASAP.

   // Replicate old pre-5.3 behaviour
   public static void SetDirty(UnityEngine.Object @object)
   {
#if UNITY_EDITOR
      //tk2dUtil.SetDirty(@object);  //take away this as it keep pointing back to itself

#if (UNITY_5_3 || UNITY_5_4 || UNITY_5_6 || UNITY_5_7 || UNITY_5_8 || UNITY_5_9 || UNITY_6_0)
      if (!string.IsNullOrEmpty(UnityEditor.AssetDatabase.GetAssetPath(@object)))
      {
         string scenePath = UnityEditor.AssetDatabase.GetAssetOrScenePath(@object);
         var scene = UnityEditor.SceneManagement.EditorSceneManager.GetSceneByPath(scenePath);
         if (scene.IsValid())
         {
            UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(scene);
         }
      }
#else
      EditorUtility.SetDirty(@object); //added this so it still functioning for previous version.
#endif

#endif  // UNITY_EDITOR
Title: Re: Unity closes (not crashes) any time I try to commit to a Sprite Collection
Post by: MBoffin on December 30, 2015, 07:54:46 am
Thank you! That definitely solved it. Just out of curiosity, though, what did you do to find that as the culprit? I'd like to be able to debug this kind of thing on my own in the future, even if I don't solve it. Just finding where it's failing would be a big help.
Title: Re: Unity closes (not crashes) any time I try to commit to a Sprite Collection
Post by: kenglou.lee on December 30, 2015, 08:59:51 am
I did a comparison with previous version that works, and dig into scripts in Editor with naming like Sprite Collection or Atlas and from there link to this file. Glad that this helps you.
Title: Re: Unity closes (not crashes) any time I try to commit to a Sprite Collection
Post by: unikronsoftware on December 31, 2015, 01:35:47 pm
Ugh, my bad. Find and replace is bad :( I shall fix that now.
Title: Re: Unity closes (not crashes) any time I try to commit to a Sprite Collection
Post by: unikronsoftware on December 31, 2015, 01:38:15 pm
The code should be
Code: [Select]
// Replicate old pre-5.3 behaviour
public static void SetDirty(UnityEngine.Object @object)
{
#if UNITY_EDITOR
UnityEditor.EditorUtility.SetDirty(@object);

#if (UNITY_5_3 || UNITY_5_4 || UNITY_5_6 || UNITY_5_7 || UNITY_5_8 || UNITY_5_9 || UNITY_6_0)
if (!string.IsNullOrEmpty(UnityEditor.AssetDatabase.GetAssetPath(@object)))
{
string scenePath = UnityEditor.AssetDatabase.GetAssetOrScenePath(@object);
var scene = UnityEditor.SceneManagement.EditorSceneManager.GetSceneByPath(scenePath);
if (scene.IsValid())
{
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(scene);
}
}
#endif

#endif // UNITY_EDITOR
}

It shouldn't be in the else.