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

System.Collections(?) misbehaving on Mac OSX builds

Discussion in 'Scripting' started by erlGrey, Jun 23, 2015.

  1. erlGrey

    erlGrey

    Joined:
    Apr 8, 2014
    Posts:
    19
    Hello all,

    I've been looking for more info on this for a while, but I'm just not getting it.

    So, I've successfully created a hashset of strings via TextAsset and everything works as expected. On Mac builds, however, not so much. I don't get any errors building the hashset, and it seems to work at first, but then it will "lose" its values and revert back to an empty hashset. On top of that, the Contains() method and I think a few others seem to have no effect/return false even when I know beyond a doubt it contains the value.

    It seems parts of .net aren't making their way over to osx? I read that I need to explicitly point it to the System.Core dll in the object using the missing class(es), but I can't figure it out... Does anyone have experience with this issue or know how to work around it?

    Any insight would be appreciated a million times over! Thanks guys.
     
  2. eisenpony

    eisenpony

    Joined:
    May 8, 2015
    Posts:
    971
    Sorry, no experience with OSX but I found a number of complaints regarding HashSet and Mono 2.

    Best I can tell, Unity is using Mono version 2.0.50727.1433 and if you look here: http://www.mono-project.com/docs/about-mono/releases/2.10.8/ it seems HashSet wasn't serializable until version 2.10

    Is there a reason you are using HashSet? It is a relatively new construct in .net. Would Dictionary<T> or List<T> suit your needs?
     
  3. erlGrey

    erlGrey

    Joined:
    Apr 8, 2014
    Posts:
    19
    Hey eisen, thanks for the response.

    Gotchya. Indeed they would. The crazy thing is I tried Dictionary and List (List wouldn't be ideal since it's not hashed but it's not that important in the scope of things) and got the exact same behavior. I even put Unity on my friend's mac, thinking it might just be a windows machine making an osx build causing the problem, but no joy. Even in his editor, it's the same behavior.
     
  4. eisenpony

    eisenpony

    Joined:
    May 8, 2015
    Posts:
    971
  5. erlGrey

    erlGrey

    Joined:
    Apr 8, 2014
    Posts:
    19
    Thanks again for the efforts, eisen, but still no luck. I went ahead and made a custom Dictionary class just in case--which is great to know about them and serialization, actually, I wasn't aware of that--but still the same. So perplexing!

    ...

    Aha! I think it's Linq that's the trouble-maker, after all. Still not sure why the dictionary occasionally resets to an empty nothing, but I replaced it with an array of strings and still had issues. Then I replaced Contains() with a foreach loop and an if statement, to test it, and voila. Hmm, I'll keep at it...

    Edit: And ToDictionary() is Linq, too! I've been googling this so long I forgot about all the linq results
     
    Last edited: Jun 23, 2015
  6. eisenpony

    eisenpony

    Joined:
    May 8, 2015
    Posts:
    971
    This sounds very suspect. Are you certain it only acts strangely on OSX?

    If you post your code someone might notice why you are getting strange behavior.
     
  7. erlGrey

    erlGrey

    Joined:
    Apr 8, 2014
    Posts:
    19
    Sure thing. Here's the original, start to finish, before I started messing with it

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Linq;
    4. using System.Collections.Generic;
    5.  
    6. public class Webster : MonoBehaviour {
    7.  
    8.     HashSet<string> webster;
    9.  
    10.     void Start ()
    11.     {
    12.         TextAsset dictFile = (TextAsset)Resources.Load ("dictionary");
    13.         webster = new HashSet<string>(dictFile.text.Split (System.Environment.NewLine.ToCharArray()));
    14.     }
    15.  
    16.     public bool IsWerd(string werd)
    17.     {
    18.         if (webster.Contains (werd)) {
    19.             return true;
    20.         }
    21.  
    22.         return false;
    23.     }
    24. }
    The other just replaces the hashsets with Dictionary<string, int> (the one line has .ToDictionary(key => key, val => 0); ), and this latest test just has string[] fart (I'm way too old for that) set to the split text, and IsWerd has the aforementioned foreach(string s in fart), if(s == fart[iterator]) etc

    Thanks again for your time, goodness.

    Another edit: And yes, it works perfectly on every (3 different) windows machine.
     
    Last edited: Jun 23, 2015