Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug iOS Build Crashing at runtime with EXC_BAD_ACCESS

Discussion in 'iOS and tvOS' started by Lucas_Rybzinski_Pinto, Mar 23, 2023.

  1. Lucas_Rybzinski_Pinto

    Lucas_Rybzinski_Pinto

    Joined:
    Dec 2, 2022
    Posts:
    5
    I am working in game and it is crashing at runtime in iOS.

    The game works perfectly in Unity and in Android Builds but when running in iOS it crashes in newer versions of Unity.

    When running the build, the Xcode stops at this point:
    upload_2023-3-23_9-48-36.png

    Going under in the stack, this Deserialization here, but the json is valid.
    upload_2023-3-23_9-47-34.png

    When using Unity 2019.4.39f1 the game works in IOS but it breaks in Unity 2021.3.16f1 and 2021.3.20f1.

    The only way for it to work in newer versions is to enable "Development Build" in the Build Settings but I can't release a game to production with this option enabled.

    Things I've tried:
    Removing Strip Engine Code, Removing Optimization in xcode
    Changing "Managed Stripping Level" to low
    Changing IL2CPP Code Generation to Faster (smaller) builds
    Updating Libraries we are using in the project
    Disabling Link Frameworks Statically in iOS Resolver
    Testing in different devices (same crash)

    To be honest I am out of ideas here. Any suggestion?
     
    ETGgames likes this.
  2. Lucas_Rybzinski_Pinto

    Lucas_Rybzinski_Pinto

    Joined:
    Dec 2, 2022
    Posts:
    5
    Update:
    It was a problema related to Threads and Deserialization.
    In our scenario instead of calling JsonConvert.DeserializeObject directly, we created a new method that "wrapped" the deserialization around a Task that passes the TaskCreationOptions.LongRunning parameter.
    Code (CSharp):
    1. public async static Task<T> Deserialize<T>(string data)
    2. {
    3.     return await Task.Factory.StartNew(() => {
    4.         return JsonConvert.DeserializeObject<T>(data);
    5.     }, TaskCreationOptions.LongRunning);
    6. }
    And adapted all old calls with new async method.

    TL;DR;
    1 - Wrap the Deserialization around a Task that passes TaskCreationOptions.LongRunning
    2 - Call this wrapped async method

    It was almost 4 weeks of work for us to figure this out, hope it helps someone somehow.
     
  3. Lucas_Rybzinski_Pinto

    Lucas_Rybzinski_Pinto

    Joined:
    Dec 2, 2022
    Posts:
    5
    Update:
    This workaround wasn't actually a solid solution.
    We've found out that the problem is actually caused by a problematic/wrong Lua compiled code in our project.