I can build correctly, but the app crashes on the device on startup. XCode shows EXC_BAD_ACCESS in the main.mm file without further information.
After some trial and error trying to isolate the crash, it seems to happen when calling the .ToString method of the object LoadAdError that is returned in the .OnAdFailedToLoad callback.
Instead of calling .ToString(), I found this also happens when calling either args.LoadAdError.GetCode() or args.LoadAdError.GetMessage() and in these cases I get a stacktrace in XCode:
args.LoadAdError.GetCode():
2021-07-08 20:23:15.868484-0300 Whiteboard[3617:639747] -[__NSArrayM code]: unrecognized selector sent to instance 0x282d32340
2021-07-08 20:23:15.928039-0300 Whiteboard[3617:639747] Uncaught exception: NSInvalidArgumentException: -[__NSArrayM code]: unrecognized selector sent to instance 0x282d32340
(
0 CoreFoundation 0x000000019aee6768 4FBDF167-161A-324C-A233-D516922C67E5 + 1218408
1 libobjc.A.dylib 0x00000001af9ad7a8 objc_exception_throw + 60
2 CoreFoundation 0x000000019ade9c3c 4FBDF167-161A-324C-A233-D516922C67E5 + 183356
3 CoreFoundation 0x000000019aee92ac 4FBDF167-161A-324C-A233-D516922C67E5 + 1229484
4 CoreFoundation 0x000000019aeeb5b0 _CF_forwarding_prep_0 + 96
5 UnityFramework 0x000000010568e38c GADUGetAdErrorCode + 20
6 UnityFramework 0x0000000102e3b8d0 LoadAdErrorClient_GetCode_mD2255678161271DD3E86983F0BB464ACD2AF3AEE + 148
7 UnityFramework 0x0000000102e273b0 AdError_GetCode_m87E2CDB24720ED604533B930922B09FB824D0AA1 + 256
8 UnityFramework 0x0000000102ed7080 U3CU3Ec__DisplayClass16_1_U3CRequestBannerU3Eb__2_m9DFB59A895CE6AD918F9C3463A0B93C89C2B499B + 792
9 UnityFramework 0x0000000103f20ed4 Action_Invoke_m3FFA5BE3D64F0FF8E1E1CB6F953913FADB5EB89E + 136
10 UnityFramework 0x0000000102eb4f40 AdmobAds_OnUpdate_mFEE93055870F86677E9E7A0BB0F547D7C46C9762 + 1188
11 UnityFramework 0x0000000102ebbca8 AdmobAds_U3C_ctorU3Eb__13_1_mC97453AB26E3739CE47C38BEC4329827417A080A + 352
12 UnityFramework 0x000000010280a13c Action_1_Invoke_mDABCC367F5B402CD2E273BD9A36D49766FA516DA_gshared + 148
13 UnityFramework 0x0000000102ac2674 Subscribe_1_OnNext_m9ADCDF2B7D99CB0AC1AA9E30E565A1CBDF3370EE_gshared + 724
14 UnityFramework 0x0000000102d509d4 FromMicroCoroutine_OnNext_m229B08F2780031647398DEADC571510476E97514_gshared + 700
15 UnityFramework 0x000000010307c6ac U3CEveryCycleCoreU3Ed__311_MoveNext_mBAF51CEEA0CC60057E0C20260AE473844AF130E7 + 1680
16 UnityFramework 0x000000010302a10c MicroCoroutine_Run_m5CA6A99C3892809AD5B6ED1AA5A3BB6D0F2F6363 + 3020
17 UnityFramework 0x000000010307b52c U3CRunUpdateMicroCoroutineU3Ed__31_MoveNext_m250E3F7B1A35682B56FBE4925C039C93EB27B03D + 756
18 UnityFramework 0x000000010370a8f8 SetupCoroutine_InvokeMoveNext_m036E6EE8C2A4D2DAA957D5702F1A3CA51313F2C7 + 1000
19 UnityFramework 0x00000001055f1c1c _ZN6il2cpp2vm7Runtime15InvokeWithThrowEPK10MethodInfoPvPS5_ + 96
20 UnityFramework 0x00000001055f1a80 _ZN6il2cpp2vm7Runtime6InvokeEPK10MethodInfoPvPS5_PP15Il2CppException + 100
21 UnityFramework 0x0000000104e517d8 _Z23scripting_method_invoke18ScriptingMethodPtr18ScriptingObjectPtrR18ScriptingArgumentsP21ScriptingExceptionPtrb + 112
22 UnityFramework 0x0000000104e60da0 _ZN19ScriptingInvocation6InvokeEP21ScriptingExceptionPtrb + 140
23 UnityFramework 0x0000000104e6f1d0 _ZN9Coroutine14InvokeMoveNextEP21ScriptingExceptionPtr + 168
24 UnityFramework 0x0000000104e6ed6c _ZN9Coroutine3RunEPb + 52
25 UnityFramework 0x00000001049e6660 _ZN18DelayedCallManager6UpdateEi + 548
26 UnityFramework 0x0000000104ba3ccc _ZZ23InitPlayerLoopCallbacksvEN49UpdateScriptRunDelayedDynamicFrameRateRegistrator7ForwardEv + 80
27 UnityFramework 0x0000000104b99fec _Z17ExecutePlayerLoopP22NativePlayerLoopSystem + 100
28 UnityFramework 0x0000000104b9a02c _Z17ExecutePlayerLoopP22NativePlayerLoopSystem + 164
29 UnityFramework 0x0000000104b9a36c _Z10PlayerLoopv + 292
30 UnityFramework 0x000000010518ae78 _ZL19UnityPlayerLoopImplb + 116
31 UnityFramework 0x000000010244f640 -[UnityAppController(Rendering) repaint] + 108
32 UnityFramework 0x000000010244f5a8 -[UnityAppController(Rendering) repaintDisplayLink] + 108
33 QuartzCore 0x000000019e1497b8 4A41F8AF-4C32-3302-BFFC-377812960921 + 83896
34 QuartzCore 0x000000019e2287f4 4A41F8AF-4C32-3302-BFFC-377812960921 + 997364
35 CoreFoundation 0x000000019ae3ba5c 4FBDF167-161A-324C-A233-D516922C67E5 + 518748
36 CoreFoundation 0x000000019ae61274 4FBDF167-161A-324C-A233-D516922C67E5 + 672372
37 CoreFoundation 0x000000019ae605f4 4FBDF167-161A-324C-A233-D516922C67E5 + 669172
38 CoreFoundation 0x000000019ae5a1d8 4FBDF167-161A-324C-A233-D516922C67E5 + 643544
39 CoreFoundation 0x000000019ae59360 CFRunLoopRunSpecific + 600
40 GraphicsServices 0x00000001b2497734 GSEventRunModal + 164
41 UIKitCore 0x000000019d8d4584 33B02AB5-5DAF-3249-8DC6-5872DF830EC5 + 12363140
42 UIKitCore 0x000000019d8d9df4 UIApplicationMain + 168
43 UnityFramework 0x000000010244f078 -[UnityFramework runUIApplicationMainWithArgc:argv:] + 108
44 Whiteboard 0x000000010205fd54 main + 68
45 libdyld.dylib 0x000000019ab15cf8 E574A365-9878-348A-8E84-91E163CFC128 + 7416
)
args.LoadAdError.GetMessage():
2021-07-08 19:46:57.310884-0300 Whiteboard[3578:626853] -[__NSArrayM localizedDescription]: unrecognized selector sent to instance 0x28233e970
2021-07-08 19:46:57.370872-0300 Whiteboard[3578:626853] Uncaught exception: NSInvalidArgumentException: -[__NSArrayM localizedDescription]: unrecognized selector sent to instance 0x28233e970
(
0 CoreFoundation 0x000000019aee6768 4FBDF167-161A-324C-A233-D516922C67E5 + 1218408
1 libobjc.A.dylib 0x00000001af9ad7a8 objc_exception_throw + 60
2 CoreFoundation 0x000000019ade9c3c 4FBDF167-161A-324C-A233-D516922C67E5 + 183356
3 CoreFoundation 0x000000019aee92ac 4FBDF167-161A-324C-A233-D516922C67E5 + 1229484
4 CoreFoundation 0x000000019aeeb5b0 _CF_forwarding_prep_0 + 96
5 UnityFramework 0x0000000108a56400 GADUGetAdErrorMessage + 24
6 UnityFramework 0x0000000106203ad8 LoadAdErrorClient_GetMessage_m9EE3D864EF992A8EBD1EEBB65E79916067678990 + 148
7 UnityFramework 0x00000001061ef6a0 AdError_GetMessage_m61542DEA318D4C9FD0DDAF905DF8913D88BFF182 + 260
8 UnityFramework 0x000000010629f080 U3CU3Ec__DisplayClass16_1_U3CRequestBannerU3Eb__2_m9DFB59A895CE6AD918F9C3463A0B93C89C2B499B + 792
9 UnityFramework 0x00000001072e8ed4 Action_Invoke_m3FFA5BE3D64F0FF8E1E1CB6F953913FADB5EB89E + 136
10 UnityFramework 0x000000010627cf40 AdmobAds_OnUpdate_mFEE93055870F86677E9E7A0BB0F547D7C46C9762 + 1188
11 UnityFramework 0x0000000106283ca8 AdmobAds_U3C_ctorU3Eb__13_1_mC97453AB26E3739CE47C38BEC4329827417A080A + 352
12 UnityFramework 0x0000000105bd213c Action_1_Invoke_mDABCC367F5B402CD2E273BD9A36D49766FA516DA_gshared + 148
13 UnityFramework 0x0000000105e8a674 Subscribe_1_OnNext_m9ADCDF2B7D99CB0AC1AA9E30E565A1CBDF3370EE_gshared + 724
14 UnityFramework 0x00000001061189d4 FromMicroCoroutine_OnNext_m229B08F2780031647398DEADC571510476E97514_gshared + 700
15 UnityFramework 0x00000001064446ac U3CEveryCycleCoreU3Ed__311_MoveNext_mBAF51CEEA0CC60057E0C20260AE473844AF130E7 + 1680
16 UnityFramework 0x00000001063f210c MicroCoroutine_Run_m5CA6A99C3892809AD5B6ED1AA5A3BB6D0F2F6363 + 3020
17 UnityFramework 0x000000010644352c U3CRunUpdateMicroCoroutineU3Ed__31_MoveNext_m250E3F7B1A35682B56FBE4925C039C93EB27B03D + 756
18 UnityFramework 0x0000000106ad28f8 SetupCoroutine_InvokeMoveNext_m036E6EE8C2A4D2DAA957D5702F1A3CA51313F2C7 + 1000
19 UnityFramework 0x00000001089b9c1c _ZN6il2cpp2vm7Runtime15InvokeWithThrowEPK10MethodInfoPvPS5_ + 96
20 UnityFramework 0x00000001089b9a80 _ZN6il2cpp2vm7Runtime6InvokeEPK10MethodInfoPvPS5_PP15Il2CppException + 100
21 UnityFramework 0x00000001082197d8 _Z23scripting_method_invoke18ScriptingMethodPtr18ScriptingObjectPtrR18ScriptingArgumentsP21ScriptingExceptionPtrb + 112
22 UnityFramework 0x0000000108228da0 _ZN19ScriptingInvocation6InvokeEP21ScriptingExceptionPtrb + 140
23 UnityFramework 0x00000001082371d0 _ZN9Coroutine14InvokeMoveNextEP21ScriptingExceptionPtr + 168
24 UnityFramework 0x0000000108236d6c _ZN9Coroutine3RunEPb + 52
25 UnityFramework 0x0000000107dae660 _ZN18DelayedCallManager6UpdateEi + 548
26 UnityFramework 0x0000000107f6bccc _ZZ23InitPlayerLoopCallbacksvEN49UpdateScriptRunDelayedDynamicFrameRateRegistrator7ForwardEv + 80
27 UnityFramework 0x0000000107f61fec _Z17ExecutePlayerLoopP22NativePlayerLoopSystem + 100
28 UnityFramework 0x0000000107f6202c _Z17ExecutePlayerLoopP22NativePlayerLoopSystem + 164
29 UnityFramework 0x0000000107f6236c _Z10PlayerLoopv + 292
30 UnityFramework 0x0000000108552e78 _ZL19UnityPlayerLoopImplb + 116
31 UnityFramework 0x0000000105817640 -[UnityAppController(Rendering) repaint] + 108
32 UnityFramework 0x00000001058175a8 -[UnityAppController(Rendering) repaintDisplayLink] + 108
33 QuartzCore 0x000000019e1497b8 4A41F8AF-4C32-3302-BFFC-377812960921 + 83896
34 QuartzCore 0x000000019e2287f4 4A41F8AF-4C32-3302-BFFC-377812960921 + 997364
35 CoreFoundation 0x000000019ae3ba5c 4FBDF167-161A-324C-A233-D516922C67E5 + 518748
36 CoreFoundation 0x000000019ae61274 4FBDF167-161A-324C-A233-D516922C67E5 + 672372
37 CoreFoundation 0x000000019ae605f4 4FBDF167-161A-324C-A233-D516922C67E5 + 669172
38 CoreFoundation 0x000000019ae5a1d8 4FBDF167-161A-324C-A233-D516922C67E5 + 643544
39 CoreFoundation 0x000000019ae59360 CFRunLoopRunSpecific + 600
40 GraphicsServices 0x00000001b2497734 GSEventRunModal + 164
41 UIKitCore 0x000000019d8d4584 33B02AB5-5DAF-3249-8DC6-5872DF830EC5 + 12363140
42 UIKitCore 0x000000019d8d9df4 UIApplicationMain + 168
43 UnityFramework 0x0000000105817078 -[UnityFramework runUIApplicationMainWithArgc:argv:] + 108
44 Whiteboard 0x000000010213fd54 main + 68
45 libdyld.dylib 0x000000019ab15cf8 E574A365-9878-348A-8E84-91E163CFC128 + 7416
)
readonly Queue<Action> mainThreadTaskQueue = new Queue<Action>();
void Start() {
RequestBanner();
}
void RequestBanner() {
var bannerView = new BannerView(bannerAdUnit, AdSize.Banner, bannerPosition);
bannerView.OnAdFailedToLoad += (_, args) => MainThread(() => Debug.Log(args.LoadAdError.ToString()));
}
void Update() {
if (mainThreadTaskQueue.Count == 0)
return;
mainThreadTaskQueue.Dequeue().Invoke();
}
void MainThread(Action action)
{
mainThreadTaskQueue.Enqueue(action);
}
Change
void RequestBanner() {
var bannerView = new BannerView(bannerAdUnit, AdSize.Banner, bannerPosition);
bannerView.OnAdFailedToLoad += (_, args) => MainThread(() => Debug.Log(args.LoadAdError.ToString()));
}
To
void RequestBanner() {
var bannerView = new BannerView(bannerAdUnit, AdSize.Banner, bannerPosition);
bannerView.OnAdFailedToLoad += (_, args) => HandleError(args);
}
void HandleError(args)
{
var msg = args.LoadAdError.ToString();
MainThread(()=> Debug.Log(msg));
}
You are running into a race condition from the error being deallocated on the iOS side. When you pass the object to another thread, you give iOS time to deallocate. By running everything same fame we resolve this issue.
We will work to solve the underlying error for a future release. Thank you, let us know if you have any additional issues.
Yes! That fix worked, thank you so much
Also had this issue, thanks so much for the workaround and the report!
@NVentimiglia this was a frustrating bug to catch. After all wrapping the ad callbacks inside MobileAdsEventExecutor.ExecuteInUpdate to not run into multi-threading issues is kind of a recommendation by the lib. Yet it produces a multi-threading issue :|
For anybody googling, the stacktrace we got initially was :
Uncaught exception: NSInvalidArgumentException: -[__NSMallocBlock__ localizedDescription]: unrecognized selector sent to instance 0x280fa4120
(
1 CoreFoundation 0x000000018385fdd4 A408A063-A023-3AAA-A674-0FF01607F818 + 1220052
1 libobjc.A.dylib 0x00000001983b77a8 objc_exception_throw + 60
2 CoreFoundation 0x00000001837632d0 A408A063-A023-3AAA-A674-0FF01607F818 + 185040
3 CoreFoundation 0x0000000183862918 A408A063-A023-3AAA-A674-0FF01607F818 + 1231128
4 CoreFoundation 0x0000000183864c10 _CF_forwarding_prep_0 + 96
5 UnityFramework 0x00000001088fbd60 GADUGetAdErrorMessage + 24
6 UnityFramework 0x0000000109280710 UnityFramework + 27789072
7 UnityFramework 0x0000000108ca9788 UnityFramework + 21665672
8 UnityFramework 0x00000001098a5a60 UnityFramework + 34232928
Most helpful comment
Change
To
You are running into a race condition from the error being deallocated on the iOS side. When you pass the object to another thread, you give iOS time to deallocate. By running everything same fame we resolve this issue.
We will work to solve the underlying error for a future release. Thank you, let us know if you have any additional issues.