-
Notifications
You must be signed in to change notification settings - Fork 257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IOS] Unity Crashes on Startup with Deep Link Launch EXC_BAD_ACCESS (code=1, address=0x378) #712
Comments
Confirm crashes at startup on SDK versions 15.1.0 and 16.0.2 and Unity 2022.3.16f1 |
Great, thank you very much, I spent so much time. Thanks for the answer |
Seems like FacebookSDK issue. I think the whole regex replacement part can be deleted from FacebookSDK, if anyone wants to make a PR. As a workaround: In the Xcode build, modify the Unity-iPhone/Classes/UnityAppController.mm Bad code: - (BOOL)isBackgroundLaunchOptions:(NSDictionary*)launchOptions
{
if (launchOptions.count == 0)
return NO;
// launch due to location event, the app likely will stay in background
BOOL locationLaunch = [[launchOptions valueForKey: UIApplicationLaunchOptionsLocationKey] boolValue];
if (locationLaunch)
return YES;
return YES; // <-- ISSUE HERE
} Good code: - (BOOL)isBackgroundLaunchOptions:(NSDictionary*)launchOptions
{
if (launchOptions.count == 0)
return NO;
// launch due to location event, the app likely will stay in background
BOOL locationLaunch = [[launchOptions valueForKey: UIApplicationLaunchOptionsLocationKey] boolValue];
if (locationLaunch)
return YES;
return NO;
} P.S It looks like Unity regression (You said 2022.3.12f1 -> 2022.3.13f1), but we just refactored our launch code around there recently, so FBSDK started modifying it randomly, which is the root cause. |
Due to Unity trampoline changes this is now misbehaving and modifying one function below (`isBackgroundLaunchOptions`) which causes a crash - see facebook#712
@xTheEc0 Was the change in the original code introduced in Unity 2022.3.13 or an earlier version? |
Thx @xTheEc0 build post process fix : [PostProcessBuild(10000)]
public static void IOSBuildPostProcess(BuildTarget target, string pathToBuiltProject)
{
.
.
FixColdStartFacebook(pathToBuiltProject); // Call this function from your IOSBuildPostProcess
.
.
}
private const string IsBackgroundLaunchOptions = @"(?x)(isBackgroundLaunchOptions.+(?:.*\n)+?\s*return\ )YES(\;\n\})# }";
public static void FixColdStartFacebook(string path)
{
string fullPath = Path.Combine(path, Path.Combine("Classes", "UnityAppController.mm"));
string data = Load(fullPath);
data = Regex.Replace(
data,
IsBackgroundLaunchOptions,
"$1NO$2");
Save(fullPath, data);
}
static string Load(string fullPath)
{
string data;
FileInfo projectFileInfo = new FileInfo(fullPath);
StreamReader fs = projectFileInfo.OpenText();
data = fs.ReadToEnd();
fs.Close();
return data;
}
static void Save(string fullPath, string data)
{
System.IO.StreamWriter writer = new System.IO.StreamWriter(fullPath, false);
writer.Write(data);
writer.Close();
} |
I launch Unity successfully from a deep link when I add this code in post process, but Application.absoluteURL is empty ( |
@mutluerdm maybe do you know ? why does it happen ? |
The change in Unity 2022.3.13 that triggered the issue is the following:
Affected versions: |
@Nezz Is it possible to somehow fix it so that the game starts on unity |
Yes, see #713 |
The crash issue would be fixed with this PR but now deeplink data isn't reaching Unity. This persists in version 2022.3.19f. |
I managed to overcome the problem by saving the deeplink in objective C and retrieving it later on C# side. In Unity C# side:
Added objective C files:
And finally updating
|
I also attempted to apply the workaround posted by @mutluerdm, but I saw the same results as @PierrePlayrion (the crash was fixed, but the deeplink was not being handled properly) To fix that I changed this line:
... to this:
and now my app links are being handled correctly. (Context: I think the original RegEx changed more than was intended, not only changing the return value of that method, but also where it was called in application:didFinishLaunchingWithOptions) Unity 2021.3.35f1 |
with your line change, I get the crash but not with the old one. I am on Unity 2022.3.19f and same FB SDK Update: Never mind, I had a callback order issue |
@pgv3n0m Could you provide the log you get? |
Nv, seems to work. I had a callback order issue I did in between the testing |
Few things I have to add:
|
In case it helps, in Unity 2022.3.22 (and possibly on other versions) the regex replace is changing both the isBackgroundLaunchOptions method and some of it's uses in the .mm file, to make sure only the method is changed you can use this regex instead:
|
Thanks to @Vitalchek for opening the issue. @sebastian-dudzic-spl and @david-a-diaz for providing the final solution and to all participants for providing your workarounds. ❤️ Community is Power ❤️ |
Hello Guys, |
@ravichandra2012 Hi, have you been able to fix deeplinks? We have the same problem after the solution from this thread |
Hey guys. |
Checklist
Environment
Goals
The application was launched via a deep link
Expected Results
The application crashes at startup. When I tried to delete the Facebook SDK, everything works perfectly. This prom=blem only on IOS, Android works fine.
Before updating to Unity 2022 and updating macOs - Sonoma and Xcode 15, it worked perfectly.
Actual Results
Error
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x378) frame #0: 0x00000001171ee5ec UnityFramework
core::StringStorageDefault::assign(char const*, unsigned long) + 28frame #1: 0x000000011791c4b8 UnityFramework
PlayerSettings::SetAbsoluteURL(core::basic_string<char, core::StringStorageDefault<char>> const&) + 44 frame #2: 0x000000011799e778 UnityFramework
UnitySetAbsoluteURL + 108frame #3: 0x00000001155073d8 UnityFramework
-[UnityAppController application:openURL:options:] + 192 frame #4: 0x000000019905e724 UIKitCore
__58-[UIApplication _applicationOpenURLAction:payload:origin:]_block_invoke + 1024frame #5: 0x000000019905e174 UIKitCore
-[UIApplication _applicationOpenURLAction:payload:origin:] + 788 frame #6: 0x000000019845c3d8 UIKitCore
-[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:] + 3256frame #7: 0x000000019845b22c UIKitCore
-[UIApplication _runWithMainScene:transitionContext:completion:] + 856 frame #8: 0x000000019845ae78 UIKitCore
-[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 132frame #9: 0x00000001983d7798 UIKitCore
_UIScenePerformActionsWithLifecycleActionMask + 112 frame #10: 0x000000019845ee74 UIKitCore
__101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke + 216frame #11: 0x0000000198386778 UIKitCore
-[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:] + 220 frame #12: 0x00000001983851f0 UIKitCore
-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:] + 608frame #13: 0x0000000198384b58 UIKitCore
-[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:] + 248 frame #14: 0x0000000198384a28 UIKitCore
__186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke + 148frame #15: 0x0000000198384930 UIKitCore
+[BSAnimationSettings(UIKit) tryAnimatingWithSettings:fromCurrentState:actions:completion:] + 736 frame #16: 0x00000001983841b8 UIKitCore
_UISceneSettingsDiffActionPerformChangesWithTransitionContextAndCompletion + 224frame #17: 0x0000000198383e68 UIKitCore
-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:] + 316 frame #18: 0x0000000198707620 UIKitCore
__64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke.225 + 612frame #19: 0x0000000198382fec UIKitCore
-[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 216 frame #20: 0x0000000198382e5c UIKitCore
-[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 244frame #21: 0x000000019849b484 UIKitCore
-[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 508 frame #22: 0x000000019849b21c UIKitCore
-[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 288frame #23: 0x00000001ae2c76d4 FrontBoardServices
-[FBSScene _callOutQueue_didCreateWithTransitionContext:completion:] + 324 frame #24: 0x00000001ae2c7570 FrontBoardServices
__92-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]_block_invoke.108 + 280frame #25: 0x00000001ae2c619c FrontBoardServices
-[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 168 frame #26: 0x00000001ae2d1f8c FrontBoardServices
__92-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]_block_invoke + 352frame #27: 0x000000019dfe5300 libdispatch.dylib
_dispatch_client_callout + 20 frame #28: 0x000000019dfe8d48 libdispatch.dylib
_dispatch_block_invoke_direct + 284frame #29: 0x00000001ae2c2520 FrontBoardServices
__FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 52 frame #30: 0x00000001ae2c24a0 FrontBoardServices
-[FBSMainRunLoopSerialQueue _targetQueue_performNextIfPossible] + 240frame #31: 0x00000001ae2c2378 FrontBoardServices
-[FBSMainRunLoopSerialQueue _performNextFromRunLoopSource] + 28 frame #32: 0x000000019605f31c CoreFoundation
CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 28frame #33: 0x000000019605e598 CoreFoundation
__CFRunLoopDoSource0 + 176 frame #34: 0x000000019605cd4c CoreFoundation
__CFRunLoopDoSources0 + 244frame #35: 0x000000019605ba88 CoreFoundation
__CFRunLoopRun + 828 frame #36: 0x000000019605b668 CoreFoundation
CFRunLoopRunSpecific + 608frame #37: 0x00000001d94265ec GraphicsServices
GSEventRunModal + 164 frame #38: 0x00000001984782b4 UIKitCore
-[UIApplication _run] + 888frame #39: 0x00000001984778f0 UIKitCore
UIApplicationMain + 340 frame #40: 0x000000011550bc0c UnityFramework
-[UnityFramework runUIApplicationMainWithArgc:argv:] + 92`The text was updated successfully, but these errors were encountered: