Search Unity

Social.LoadAchievements crashes.

Discussion in 'iOS and tvOS' started by sdf_eee, May 24, 2017.

  1. sdf_eee

    sdf_eee

    Joined:
    May 30, 2015
    Posts:
    55
    I faced a very strange situation during my development.
    My app is using unity internal Social module like below.

    Code (CSharp):
    1. public void Init()
    2. {
    3.     if (Social.localUser.authenticated)
    4.     {
    5.         LoadAchievements();
    6.     }
    7. }
    8.  
    9. void LoadAchievements()
    10. {
    11.     Social.LoadAchievements(achievements =>
    12.     {
    13.         if (achievements == null)
    14.         {
    15.             return;
    16.         }
    17.  
    18.         if (0 < achievements.Length)
    19.         {
    20.             for (int i = 0; i < achievements.Length; ++i)
    21.             {
    22.                 // do something
    23.             }
    24.         }
    25.     });
    26. }
    Condition:
    - Unity 5.6.1(f1, p1):
    - IL2CPP
    - My app is not on iTunesConnect. So the GameCenter does not know about this app.
    (but this was not a problem in the past.)
    - Also my app dosen't have achievements.
    - This is because BundleIdentifier for Appstore and development are different. ex) com.sdf.rb.dev / com.sdf.rb

    There was no problem in the first run. However, when I press the Home button to close the app,
    and the second time it launches, it crashes in Social.LoadAchievements.
    It seems does not reach the my callback. (anonymous delegate passed by parameter.)
    And once this happens, it happens continually.

    I attached full crash report log.
    plz help me, I spent a lot of time on this problem.
     

    Attached Files:

    Last edited: May 29, 2017
  2. PixelEnvision

    PixelEnvision

    Joined:
    Feb 7, 2012
    Posts:
    513
    Try calling LoadAchievements function with a delay of 1 second. I had a similar crash and solved it that way...
     
  3. sdf_eee

    sdf_eee

    Joined:
    May 30, 2015
    Posts:
    55
    Last edited: May 29, 2017
  4. sdf_eee

    sdf_eee

    Joined:
    May 30, 2015
    Posts:
    55
    I found more information. Social.LoadAchievements(null); is never crashes.
    In addition, I attach two types of crash reports that are probably caused by this issue.
     

    Attached Files:

  5. PixelEnvision

    PixelEnvision

    Joined:
    Feb 7, 2012
    Posts:
    513
    What I meant was, just make your load achievements a coroutine and call it with a delay, after authentication.

    Something like
    Code (CSharp):
    1. public void Init()
    2. {
    3.     if (Social.localUser.authenticated)
    4.     {
    5.        StartCoroutine("LoadAchievements", 1.0f);
    6.     }
    7. }
    8. IEnumerator LoadAchievements()
    9. {
    10. ....
    11. }
     
  6. sdf_eee

    sdf_eee

    Joined:
    May 30, 2015
    Posts:
    55
    Unfortunately, It does not work for me.
     
  7. jeremyburgesspp

    jeremyburgesspp

    Joined:
    Jul 1, 2014
    Posts:
    2
    We're seeing the same crash, though for us it's very intermittent. We're also seeing another (related) crash.
    • We're running 5.6.2p2.
    • We're seeing it in 2 apps with very different code.
    • One of those apps was previously on 5.4 and utilises the Crashlytics crash reporting service - these crashes are new with the 5.6 build.
    • Our affected apps are on iTunes Connect & have achievements setup correctly.
    I have just filed a bug - if it gets a public IssueTracker link I'll post it here.
     
  8. SimonFireproof

    SimonFireproof

    Joined:
    May 20, 2013
    Posts:
    16
    I think I'm getting the same crash in 5.6.3p1. Anyone got more news on this issue?

    Thanks!
     
  9. Deepscorn

    Deepscorn

    Joined:
    Aug 13, 2015
    Posts:
    25
    Same in Unity 5.6.2f1. We had that crash http://crashes.to/s/606c5902c62. Then we refactored code and saw that crash logs:
    http://crashes.to/s/edad702ee0d (same as above, but here we see that callback, passed to Social.LoadAchievements is called from cpp code and crashes)
    http://crashes.to/s/40ad7dd5f11 (that's MemoryAccessException in the code inside that callback)
    http://crashes.to/s/4cc103bf6c6 (that's MemoryAccessException in the same code inside that callback)

    I think, that when callback, passed in Social.LoadAchievements is called from cpp code, it have limitations on the code/memory use. Maybe better not to do it an anonymous function (lambda), but pass regular method. And maybe add something like internal [UnityEngine.Scripting.RequiredByNativeCode] attribute (just a guess). And make that callback access as less things as possible (so it wount produce MemoryAccessException). For example:

    class A
    {
    private IAchievement[] achievements;

    public void DoSome()
    {
    Social.LoadAchievements(OnLoadAchievements);
    }

    public void OnLoadAchievements(IAchievement[] platformAchievements)
    {
    achievements = platformAchievements;
    }
    }
     
  10. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    We're experiencing this as well but i am unable to use the attribute RequiredByNativeCode even with the UnityEngine.Scripting namespace.....any other workarounds to this?
     
  11. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    *We're on 5.6.4p3