iOS Build Crashing at runtime with EXC_BAD_ACCESS

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:

Going under in the stack, this Deserialization here, but the json is valid.

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?

1 Like

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.

public async static Task<T> Deserialize<T>(string data)
{
    return await Task.Factory.StartNew(() => {
        return JsonConvert.DeserializeObject<T>(data);
    }, TaskCreationOptions.LongRunning);
}

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.

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.