Search Unity

Bug in Mono on certain Android devices with IEnumerable

Discussion in 'Scripting' started by michael-v, Jun 30, 2014.

  1. michael-v

    michael-v

    Joined:
    Jun 21, 2013
    Posts:
    19
    Suddenly, after moving to Unity 4.5 our app started to crash violently on galaxy s4 and other top devices on android. Investigation showed that crash was the result of wrong iterator type in our json library (json.fx). Quick googling showed that this error is present and active. Further investigation showed that after some unknown trigger-event following casts returned wrong type:

    var x = new Dictionatry<string, object>();
    ((IEnumerable)((IDictionary)x)) -> KeyCollection

    First cast to IDictionary results in ShimEnumerator which to my understaning is some mono hack to intertwine generic and non-generic dictionaries. Casting ShimEnumerator to IEnumerable produces KeyCollection, not Dictionary enumerator and it doesn't implement IDictionaryEnumerator.

    All we did is just removed cast to IEnumerable (we don't use non-generic types in serialization) and it works as expected.

    Hope that helps and will raise some flags to mono integration team.

    PS: All other implementations of json parsers/writers start to crash as well, it's not json.fx specific error. Not that it's json specific error as well, we just don't have any other reflection-based code except this libraries.
     
  2. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Be worth submitting this as a bug report.
     
  3. michael-v

    michael-v

    Joined:
    Jun 21, 2013
    Posts:
    19
    I will, but i can't reproduce it outside of our project, which i can't attach due to obvious reasons.
     
  4. michael-v

    michael-v

    Joined:
    Jun 21, 2013
    Posts:
    19
    I posted bug report.

    I want to also note that Android is never crashed from our mono errors until now, all errors was handled by unity game loop somewhere and stacktrace in console was all that happened. But trying to do foreach on resulting itterator CRASHES the game.
     
  5. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    My JSON .NET port does not suffer from this issue and doesn't have any issues with generic collections on Android that I've been made aware of.