Skip to content
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

Using most System.IO file classes will crash on iOS devices (not in the simulator) #40757

Closed
andy-noisyduck opened this issue Jul 27, 2020 · 20 comments

Comments

@andy-noisyduck
Copy link
Contributor

Godot version:
3.2.2 Mono w/ Mono 6.10 stable

OS/device including version:
Build w/ OSX Catalina, tested on various iPhones w/ iOS 13

Issue description:
App will crash when using most of the System.IO classes, such as File or FileStream. This only happens on real devices. The simulator works fine.

The crash occurs any time the framework needs to call the native Stat method to check if a file exists (and most of the File classes do this on creation to know whether to overwrite, append, or throw depending on modes passed).

SystemNative_Stat2
  at Interop+Sys.Stat (System.ReadOnlySpan`1[T] path, Interop+Sys+FileStatus& output)
  at System.IO.FileSystem.FileExists (System.ReadOnlySpan`1[T] fullPath, System.Int32 fileType, Interop+ErrorInfo& errorInfo)
  at System.IO.FileSystem.DirectoryExists (System.ReadOnlySpan`1[T] fullPath, Interop+ErrorInfo& errorInfo)
  at System.IO.FileSystem.DirectoryExists (System.ReadOnlySpan`1[T] fullPath)
  at System.IO.Directory.Exists (System.String path)
  at System.IO.FileStream..ctor (System.String path, System.IO.FileMode)

As with #40633, I am unsure whether this is a problem with the way Godot is using Mono, a symptom of AoT (required for iOS), or a problem with the Mono implementation on iOS. I am starting to think it's related and that's its a linking or packaging problem for native methods on iOS.

It's not clear to me which versions of libmono get packed if your local Mono install doesn't match the pre-compiled export template (in my case 6.10 vs 6.8). I also tried this matching my local Mono version to the template. The issue still occurred.

Steps to reproduce:

  1. Open a file in OpenCreate modes (other modes should also trigger this). e.g. new FileStream(Path.Combine(".test"), FileMode.OpenOrCreate);

Minimal reproduction project:
Test-MonoFileIOS.zip

@naithar
Copy link
Contributor

naithar commented Jul 28, 2020

I can't reproduce the crash with newly downloaded Godot and newly exported project. Tested on iPhone 6 (iOS 12) and iPhone XS (iOS 13).
Same as #40633 I see a text edit with OK! in it.
It does however crash on closing the application in mono_debug_domain_unload, but not on start when FileStream or Random get's called.

@andy-noisyduck
Copy link
Contributor Author

Interesting. Which Mono version have you built with?

@naithar
Copy link
Contributor

naithar commented Jul 29, 2020

I didn't install any specific version of Mono or specified anything specific to it in Xcode project.
As I said, I've just downloaded a Godot version with Mono and made a clean export of the project you provided.
Resulted Xcode project seems to have a mono libraries imported as static library and application works just fine on both devices and simulator.

Well, I have a mono that got installed with Xamarin, but it's hardly relevant

Mono JIT compiler version 5.16.0.221 (2018-06/b63e5378e38 Mon Nov 19 18:08:09 EST 2018)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com

@andy-noisyduck
Copy link
Contributor Author

Well, I have a mono that got installed with Xamarin, but it's hardly relevant

Is it not? My understanding is that the Mono assemblies that get bundled with your app (including System and mscorlib) are the ones from your local Mono distribution. The export template only contains the precompiled libmono and associated shared libraries for the native entry points. I'm not sure how it works if your assemblies are not matched with the shared libs in the export template. Perhaps I'm misunderstanding how it works?

The broken SystemNative_Stat2 from this ticket is a decent example. It was renamed from Stat due to a breaking change somwhere around Mono 6.8 if I recall. I have no idea which version is in the export template library. Would this be the expected error if the assemblies are from 6.10 and libmono is older?

As I said, I've just downloaded a Godot version with Mono and made a clean export of the project you provided.

By coincidence, I ended up with a fresh Mac today. I tried a new install with the setup you described (Godot 3.2.2, Mono 5.16.0.220, and latest Xcode). I still get a crash on the device under this scenario (but again, not in the simulator). I am unsure why we are getting different results.

@naithar
Copy link
Contributor

naithar commented Jul 30, 2020

Is it not? My understanding is that the Mono assemblies that get bundled with your app (including System and mscorlib) are the ones from your local Mono distribution.

I think it's not, because resulting Xcode project does not have any additional rules for compilation or asset bundling other than just statically linking five libmono libraries and having some additional code in dummy.cpp. I would expect it to have something in Build Phases if it did bundle something from build machine.
That's why I thinks everything is already bundled in static libraries that come with exported project.
I think it would also crash on startup without even getting to Godot's setup if something wasn't really bundled correctly, since iOS loads dynamic libraries on startup.

Maybe running iOS app with --verbose flag can give more details on why this crash is happening.

@naithar
Copy link
Contributor

naithar commented Jul 30, 2020

I'm also not sure why we are having different results, but maybe you can try using Xcode project that I've exported:
https://www.dropbox.com/s/6zx3yne0z8augmb/test_mono.zip?dl=0

@andy-noisyduck
Copy link
Contributor Author

andy-noisyduck commented Jul 30, 2020

Xcode project does not have any additional rules for compilation or asset bundling other than just statically linking five libmono libraries and having some additional code in dummy.cpp. I would expect it to have something in Build Phases if it did bundle something from build machine. That's why I thinks everything is already bundled in static libraries that come with exported project.

My understanding is that the .Net assemblies are run through AoT and then built into a static library that Xcode then uses in the build (lib-aot-<project>.fat.a). Xcode doesn't need to do any additional steps beyond including the (already built) library, so I wouldn't expect to see it in the Build Phases. Perhaps @neikeq can clarify this when time permits.

I'm also not sure why we are having different results, but maybe you can try using Xcode project that I've exported:
https://www.dropbox.com/s/6zx3yne0z8augmb/test_mono.zip?dl=0

Perfect. I was going to ask if you would mind putting your project up for me to try.

Thanks for helping investigate this.

@andy-noisyduck
Copy link
Contributor Author

I'm also not sure why we are having different results, but maybe you can try using Xcode project that I've exported:
https://www.dropbox.com/s/6zx3yne0z8augmb/test_mono.zip?dl=0

Your project crashes on my device (with the same exception from the ticket). I didn't expect that result, and I am not sure where to go from here.

@naithar
Copy link
Contributor

naithar commented Jul 30, 2020

Ok, I think I've managed to break the project :)
Now I receive this error on app startup:

2020-07-30 20:42:13.945985+0300 Test-MonoIos[16948:7644920] Mono: Initializing module...
Mono: Initializing module...
2020-07-30 20:42:13.947447+0300 Test-MonoIos[16948:7644920] Mono JIT compiler version 6.6.0 ((no/d9001b5a)
Mono JIT compiler version 6.6.0 ((no/d9001b5a)
2020-07-30 20:42:13.953888+0300 Test-MonoIos[16948:7644920] **ERROR**: Mono: Core API hash mismatch.
2020-07-30 20:42:13.953908+0300 Test-MonoIos[16948:7644920]    At: modules/mono/mono_gd/gd_mono.cpp:494:_init_godot_api_hashes() - Mono: Core API hash mismatch.
**ERROR**: Mono: Core API hash mismatch.
   At: modules/mono/mono_gd/gd_mono.cpp:494:_init_godot_api_hashes() - Mono: Core API hash mismatch.
2020-07-30 20:42:13.955062+0300 Test-MonoIos[16948:7644920] Mono: Config attempting to parse: '/private/var/containers/Bundle/Application/98184671-601E-45BE-8EEF-18EA0FCE18D0/Test-MonoIos.app/data_Godot/Mono/etc/mono/config'.
2020-07-30 20:42:13.955115+0300 Test-MonoIos[16948:7644920] Mono: Config attempting to parse: '/private/var/mobile/Containers/Data/Application/5111ADF7-2F64-418B-B9C2-74234A610483/.mono/config'.
2020-07-30 20:42:13.972260+0300 Test-MonoIos[16948:7644920] Mono: Image addref mscorlib[0x282786b80] (asmctx DEFAULT) -> .mono/assemblies/Debug/mscorlib.dll[0x13c8bfe00]: 2
2020-07-30 20:42:13.972321+0300 Test-MonoIos[16948:7644920] Mono: Prepared to set up assembly 'mscorlib' (.mono/assemblies/Debug/mscorlib.dll)
2020-07-30 20:42:13.972345+0300 Test-MonoIos[16948:7644920] Mono: Found statically linked AOT module 'mscorlib'.
2020-07-30 20:42:13.975933+0300 Test-MonoIos[16948:7644920] Mono: Unloading image .mono/assemblies/Debug/mscorlib.dll [0x13c8c4400].
2020-07-30 20:42:13.976082+0300 Test-MonoIos[16948:7644920] Mono: Image addref mscorlib[0x282786c80] (asmctx DEFAULT) -> .mono/assemblies/Debug/mscorlib.dll[0x13c8bfe00]: 4
2020-07-30 20:42:13.976217+0300 Test-MonoIos[16948:7644920] Mono: AOT: image 'mscorlib' found.
2020-07-30 20:42:13.989913+0300 Test-MonoIos[16948:7644920] Mono: Assembly mscorlib[0x282786b80] added to domain GodotEngine.RootDomain, ref_count=1
2020-07-30 20:42:13.989959+0300 Test-MonoIos[16948:7644920] Mono: Runtime initialized
Mono: Runtime initialized
2020-07-30 20:42:13.989973+0300 Test-MonoIos[16948:7644920] Mono: Loading assembly mscorlib...
Mono: Loading assembly mscorlib...
2020-07-30 20:42:13.989987+0300 Test-MonoIos[16948:7644920] Mono: Assembly mscorlib loaded from path: .mono/assemblies/Debug/mscorlib.dll
Mono: Assembly mscorlib loaded from path: .mono/assemblies/Debug/mscorlib.dll
2020-07-30 20:42:13.990517+0300 Test-MonoIos[16948:7644920] Mono: INITIALIZED
Mono: INITIALIZED
2020-07-30 20:42:13.990530+0300 Test-MonoIos[16948:7644920] Mono: Loading assembly GodotSharp...
Mono: Loading assembly GodotSharp...
2020-07-30 20:42:13.997434+0300 Test-MonoIos[16948:7644920] Mono: Image addref GodotSharp[0x2827b0d00] (asmctx DEFAULT) -> .mono/assemblies/Debug/GodotSharp.dll[0x13c0a7e00]: 2
2020-07-30 20:42:13.997460+0300 Test-MonoIos[16948:7644920] Mono: Prepared to set up assembly 'GodotSharp' (.mono/assemblies/Debug/GodotSharp.dll)
2020-07-30 20:42:13.997469+0300 Test-MonoIos[16948:7644920] Mono: Assembly GodotSharp[0x2827b0d00] added to domain GodotEngine.RootDomain, ref_count=1
2020-07-30 20:42:13.997478+0300 Test-MonoIos[16948:7644920] Mono: Found statically linked AOT module 'GodotSharp'.
2020-07-30 20:42:14.002316+0300 Test-MonoIos[16948:7644920] Mono: Image addref System[0x2827b0f00] (asmctx DEFAULT) -> .mono/assemblies/Debug/System.dll[0x13c0a8600]: 2
2020-07-30 20:42:14.002341+0300 Test-MonoIos[16948:7644920] Mono: Prepared to set up assembly 'System' (.mono/assemblies/Debug/System.dll)
2020-07-30 20:42:14.002350+0300 Test-MonoIos[16948:7644920] Mono: Assembly System[0x2827b0f00] added to domain GodotEngine.RootDomain, ref_count=1
2020-07-30 20:42:14.002358+0300 Test-MonoIos[16948:7644920] Mono: Found statically linked AOT module 'System'.
2020-07-30 20:42:14.004929+0300 Test-MonoIos[16948:7644920] Mono: Image addref Mono.Security[0x2827b1100] (asmctx DEFAULT) -> .mono/assemblies/Debug/Mono.Security.dll[0x13c0aaa00]: 2
2020-07-30 20:42:14.004944+0300 Test-MonoIos[16948:7644920] Mono: Prepared to set up assembly 'Mono.Security' (.mono/assemblies/Debug/Mono.Security.dll)
2020-07-30 20:42:14.004953+0300 Test-MonoIos[16948:7644920] Mono: Assembly Mono.Security[0x2827b1100] added to domain GodotEngine.RootDomain, ref_count=1
2020-07-30 20:42:14.004960+0300 Test-MonoIos[16948:7644920] Mono: Found statically linked AOT module 'Mono.Security'.
2020-07-30 20:42:14.005630+0300 Test-MonoIos[16948:7644920] Mono: AOT: image 'Mono.Security' found.
2020-07-30 20:42:14.006157+0300 Test-MonoIos[16948:7644920] Mono: Image addref System.Core[0x2827b1300] (asmctx DEFAULT) -> .mono/assemblies/Debug/System.Core.dll[0x13c0ab200]: 2
2020-07-30 20:42:14.006169+0300 Test-MonoIos[16948:7644920] Mono: Prepared to set up assembly 'System.Core' (.mono/assemblies/Debug/System.Core.dll)
2020-07-30 20:42:14.006176+0300 Test-MonoIos[16948:7644920] Mono: Assembly System.Core[0x2827b1300] added to domain GodotEngine.RootDomain, ref_count=1
2020-07-30 20:42:14.006184+0300 Test-MonoIos[16948:7644920] Mono: Found statically linked AOT module 'System.Core'.
2020-07-30 20:42:14.007352+0300 Test-MonoIos[16948:7644920] Mono: AOT: image 'System.Core' found.
2020-07-30 20:42:14.008242+0300 Test-MonoIos[16948:7644920] Mono: Image addref System.Numerics[0x282786f80] (asmctx DEFAULT) -> .mono/assemblies/Debug/System.Numerics.dll[0x13c8eb200]: 2
2020-07-30 20:42:14.008255+0300 Test-MonoIos[16948:7644920] Mono: Prepared to set up assembly 'System.Numerics' (.mono/assemblies/Debug/System.Numerics.dll)
2020-07-30 20:42:14.008263+0300 Test-MonoIos[16948:7644920] Mono: Assembly System.Numerics[0x282786f80] added to domain GodotEngine.RootDomain, ref_count=1
2020-07-30 20:42:14.008270+0300 Test-MonoIos[16948:7644920] Mono: Found statically linked AOT module 'System.Numerics'.
2020-07-30 20:42:14.008568+0300 Test-MonoIos[16948:7644920] Mono: AOT: image 'System.Numerics' found.
2020-07-30 20:42:14.008586+0300 Test-MonoIos[16948:7644920] Mono: AOT: image 'System' found.
2020-07-30 20:42:14.008626+0300 Test-MonoIos[16948:7644920] Mono: AOT: image 'GodotSharp' found.
2020-07-30 20:42:14.008698+0300 Test-MonoIos[16948:7644920] Mono: Assembly GodotSharp loaded from path: .mono/assemblies/Debug/GodotSharp.dll
Mono: Assembly GodotSharp loaded from path: .mono/assemblies/Debug/GodotSharp.dll
2020-07-30 20:42:14.008734+0300 Test-MonoIos[16948:7644920] Mono: Loading reference 0 of .mono/assemblies/Debug/GodotSharp.dll asmctx DEFAULT, looking for mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
2020-07-30 20:42:14.008744+0300 Test-MonoIos[16948:7644920] Mono: Assembly Ref addref GodotSharp[0x2827b0d00] -> mscorlib[0x282786b80]: 2
2020-07-30 20:42:14.009271+0300 Test-MonoIos[16948:7644920] Mono: Loading reference 2 of .mono/assemblies/Debug/GodotSharp.dll asmctx DEFAULT, looking for System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
2020-07-30 20:42:14.009284+0300 Test-MonoIos[16948:7644920] Mono: Assembly Ref addref GodotSharp[0x2827b0d00] -> System[0x2827b0f00]: 2
2020-07-30 20:42:14.009465+0300 Test-MonoIos[16948:7644920] Mono: Loading reference 0 of .mono/assemblies/Debug/System.dll asmctx DEFAULT, looking for mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
2020-07-30 20:42:14.009476+0300 Test-MonoIos[16948:7644920] Mono: Assembly Ref addref System[0x2827b0f00] -> mscorlib[0x282786b80]: 3
2020-07-30 20:42:14.023530+0300 Test-MonoIos[16948:7644920] Mono: Loading reference 0 of .mono/assemblies/Debug/System.Core.dll asmctx DEFAULT, looking for mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
2020-07-30 20:42:14.023560+0300 Test-MonoIos[16948:7644920] Mono: Assembly Ref addref System.Core[0x2827b1300] -> mscorlib[0x282786b80]: 4
2020-07-30 20:42:14.038957+0300 Test-MonoIos[16948:7644920] Mono: Loading assembly Test-MonoIos...
Mono: Loading assembly Test-MonoIos...
2020-07-30 20:42:14.039233+0300 Test-MonoIos[16948:7644920] Mono: Image addref Test-MonoIos[0x282787180] (asmctx DEFAULT) -> .mono/assemblies/Debug/Test-MonoIos.dll[0x13c927e00]: 2
2020-07-30 20:42:14.039247+0300 Test-MonoIos[16948:7644920] Mono: Prepared to set up assembly 'Test-MonoIos' (.mono/assemblies/Debug/Test-MonoIos.dll)
2020-07-30 20:42:14.039255+0300 Test-MonoIos[16948:7644920] Mono: Assembly Test-MonoIos[0x282787180] added to domain GodotEngine.RootDomain, ref_count=1
2020-07-30 20:42:14.039264+0300 Test-MonoIos[16948:7644920] Mono: Found statically linked AOT module 'Test-MonoIos'.
2020-07-30 20:42:14.039273+0300 Test-MonoIos[16948:7644920] Failed to load AOT module 'Test-MonoIos' while running in aot-only mode: doesn't match assembly.
2020-07-30 20:42:14.039291+0300 Test-MonoIos[16948:7644920] Failed to load AOT module 'Test-MonoIos' while running in aot-only mode: doesn't match assembly.

@naithar
Copy link
Contributor

naithar commented Jul 30, 2020

@andy-noisyduck try this build. I've enabled all options in Godot under Mono->Export settings menu and made a clean export.
This build now works fine.

Test-MonoFileIOS_edited.zip
https://www.dropbox.com/s/ma9ga96dz2hbnx0/build2.zip?dl=0

@andy-noisyduck
Copy link
Contributor Author

@andy-noisyduck try this build. I've enabled all options in Godot under Mono->Export settings menu and made a clean export. This build now works fine.

I get the exception again on my device. I'm going to try and get hold of a different device over the weekend. I want to rule out having an odd device somehow.

@naithar
Copy link
Contributor

naithar commented Jul 30, 2020

Try to enable the options and make a clean export yourself. And don't forget to clean DerivedData, it could also be breaking the build.
And giving the logs would probably help in identifying the problem too. :)

@andy-noisyduck
Copy link
Contributor Author

Most of the Mono->Export options are actually ignored when building for iOS as AOT is always required. It's only optional for other platforms.

FullAot = platform == OS.Platforms.iOS || (bool)(ProjectSettings.GetSetting("mono/export/aot/full_aot") ?? false)

Out of curiosity, I just tried the build on an AWS Device Farm iPhone, and I also get the exception there (with either your project or mine).

I'll still try and get another physical device over the weekend and I'll grab the logs from it. Not sure how else to narrow this down. It would also be interesting if a 3rd person could build the project and see what results they get.

@naithar
Copy link
Contributor

naithar commented Jul 30, 2020

If you would be able to give a logs from console, that could help too.

After I've changed project settings my logs look like this:


2020-07-30 21:36:21.993503+0300 Test-MonoIos[17012:7664742] **ERROR**: Mono: Core API hash mismatch.
2020-07-30 21:36:21.993539+0300 Test-MonoIos[17012:7664742]    At: modules/mono/mono_gd/gd_mono.cpp:494:_init_godot_api_hashes() - Mono: Core API hash mismatch.
**ERROR**: Mono: Core API hash mismatch.
   At: modules/mono/mono_gd/gd_mono.cpp:494:_init_godot_api_hashes() - Mono: Core API hash mismatch.
2020-07-30 21:36:21.995695+0300 Test-MonoIos[17012:7664742] Mono: Config attempting to parse: '/private/var/containers/Bundle/Application/A49418B7-C0F7-46EE-A6C5-A92885597AC7/Test-MonoIos.app/data_Godot/Mono/etc/mono/config'.
2020-07-30 21:36:21.995746+0300 Test-MonoIos[17012:7664742] Mono: Config attempting to parse: '/private/var/mobile/Containers/Data/Application/1E4ED6E9-FEF8-4C50-A6EE-E7A00856D27F/.mono/config'.
2020-07-30 21:36:22.013873+0300 Test-MonoIos[17012:7664742] Mono: Image addref mscorlib[0x280c4f000] (asmctx DEFAULT) -> .mono/assemblies/Debug/mscorlib.dll[0x10f86fe00]: 2
2020-07-30 21:36:22.014511+0300 Test-MonoIos[17012:7664742] Mono: Prepared to set up assembly 'mscorlib' (.mono/assemblies/Debug/mscorlib.dll)
2020-07-30 21:36:22.015297+0300 Test-MonoIos[17012:7664742] Mono: Found statically linked AOT module 'mscorlib'.
2020-07-30 21:36:22.028016+0300 Test-MonoIos[17012:7664742] Mono: Unloading image .mono/assemblies/Debug/mscorlib.dll [0x10f860e00].
2020-07-30 21:36:22.028192+0300 Test-MonoIos[17012:7664742] Mono: Image addref mscorlib[0x280c46c00] (asmctx DEFAULT) -> .mono/assemblies/Debug/mscorlib.dll[0x10f86fe00]: 4
2020-07-30 21:36:22.028315+0300 Test-MonoIos[17012:7664742] Mono: AOT: image 'mscorlib' found.
2020-07-30 21:36:22.045434+0300 Test-MonoIos[17012:7664742] Mono: Assembly mscorlib[0x280c4f000] added to domain GodotEngine.RootDomain, ref_count=1
2020-07-30 21:36:22.052848+0300 Test-MonoIos[17012:7664742] Mono: Image addref GodotSharp[0x280c46d00] (asmctx DEFAULT) -> .mono/assemblies/Debug/GodotSharp.dll[0x10f873200]: 2
2020-07-30 21:36:22.052872+0300 Test-MonoIos[17012:7664742] Mono: Prepared to set up assembly 'GodotSharp' (.mono/assemblies/Debug/GodotSharp.dll)
2020-07-30 21:36:22.052881+0300 Test-MonoIos[17012:7664742] Mono: Assembly GodotSharp[0x280c46d00] added to domain GodotEngine.RootDomain, ref_count=1
2020-07-30 21:36:22.052889+0300 Test-MonoIos[17012:7664742] Mono: Found statically linked AOT module 'GodotSharp'.
2020-07-30 21:36:22.067232+0300 Test-MonoIos[17012:7664742] Mono: Image addref System[0x280c46f00] (asmctx DEFAULT) -> .mono/assemblies/Debug/System.dll[0x10f85fe00]: 2
2020-07-30 21:36:22.067261+0300 Test-MonoIos[17012:7664742] Mono: Prepared to set up assembly 'System' (.mono/assemblies/Debug/System.dll)
2020-07-30 21:36:22.067273+0300 Test-MonoIos[17012:7664742] Mono: Assembly System[0x280c46f00] added to domain GodotEngine.RootDomain, ref_count=1
2020-07-30 21:36:22.067283+0300 Test-MonoIos[17012:7664742] Mono: Found statically linked AOT module 'System'.
2020-07-30 21:36:22.071895+0300 Test-MonoIos[17012:7664742] Mono: Image addref Mono.Security[0x280c47100] (asmctx DEFAULT) -> .mono/assemblies/Debug/Mono.Security.dll[0x10f860c00]: 2
2020-07-30 21:36:22.071910+0300 Test-MonoIos[17012:7664742] Mono: Prepared to set up assembly 'Mono.Security' (.mono/assemblies/Debug/Mono.Security.dll)
2020-07-30 21:36:22.071920+0300 Test-MonoIos[17012:7664742] Mono: Assembly Mono.Security[0x280c47100] added to domain GodotEngine.RootDomain, ref_count=1
2020-07-30 21:36:22.071927+0300 Test-MonoIos[17012:7664742] Mono: Found statically linked AOT module 'Mono.Security'.
2020-07-30 21:36:22.073674+0300 Test-MonoIos[17012:7664742] Mono: AOT: image 'Mono.Security' found.
2020-07-30 21:36:22.081181+0300 Test-MonoIos[17012:7664742] Mono: Image addref System.Core[0x280c47300] (asmctx DEFAULT) -> .mono/assemblies/Debug/System.Core.dll[0x10f873a00]: 2
2020-07-30 21:36:22.081390+0300 Test-MonoIos[17012:7664742] Mono: Prepared to set up assembly 'System.Core' (.mono/assemblies/Debug/System.Core.dll)
2020-07-30 21:36:22.081398+0300 Test-MonoIos[17012:7664742] Mono: Assembly System.Core[0x280c47300] added to domain GodotEngine.RootDomain, ref_count=1
2020-07-30 21:36:22.081406+0300 Test-MonoIos[17012:7664742] Mono: Found statically linked AOT module 'System.Core'.
2020-07-30 21:36:22.085805+0300 Test-MonoIos[17012:7664742] Mono: AOT: image 'System.Core' found.
2020-07-30 21:36:22.086918+0300 Test-MonoIos[17012:7664742] Mono: Image addref System.Numerics[0x280c4f380] (asmctx DEFAULT) -> .mono/assemblies/Debug/System.Numerics.dll[0x10f0df400]: 2
2020-07-30 21:36:22.086932+0300 Test-MonoIos[17012:7664742] Mono: Prepared to set up assembly 'System.Numerics' (.mono/assemblies/Debug/System.Numerics.dll)
2020-07-30 21:36:22.086942+0300 Test-MonoIos[17012:7664742] Mono: Assembly System.Numerics[0x280c4f380] added to domain GodotEngine.RootDomain, ref_count=1
2020-07-30 21:36:22.086950+0300 Test-MonoIos[17012:7664742] Mono: Found statically linked AOT module 'System.Numerics'.
2020-07-30 21:36:22.087684+0300 Test-MonoIos[17012:7664742] Mono: AOT: image 'System.Numerics' found.
2020-07-30 21:36:22.087702+0300 Test-MonoIos[17012:7664742] Mono: AOT: image 'System' found.
2020-07-30 21:36:22.087769+0300 Test-MonoIos[17012:7664742] Mono: AOT: image 'GodotSharp' found.
2020-07-30 21:36:22.087940+0300 Test-MonoIos[17012:7664742] Mono: Loading reference 0 of .mono/assemblies/Debug/GodotSharp.dll asmctx DEFAULT, looking for mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
2020-07-30 21:36:22.087954+0300 Test-MonoIos[17012:7664742] Mono: Assembly Ref addref GodotSharp[0x280c46d00] -> mscorlib[0x280c4f000]: 2
2020-07-30 21:36:22.088539+0300 Test-MonoIos[17012:7664742] Mono: Loading reference 2 of .mono/assemblies/Debug/GodotSharp.dll asmctx DEFAULT, looking for System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
2020-07-30 21:36:22.088553+0300 Test-MonoIos[17012:7664742] Mono: Assembly Ref addref GodotSharp[0x280c46d00] -> System[0x280c46f00]: 2
2020-07-30 21:36:22.088756+0300 Test-MonoIos[17012:7664742] Mono: Loading reference 0 of .mono/assemblies/Debug/System.dll asmctx DEFAULT, looking for mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
2020-07-30 21:36:22.088770+0300 Test-MonoIos[17012:7664742] Mono: Assembly Ref addref System[0x280c46f00] -> mscorlib[0x280c4f000]: 3
2020-07-30 21:36:22.108672+0300 Test-MonoIos[17012:7664742] Mono: Loading reference 0 of .mono/assemblies/Debug/System.Core.dll asmctx DEFAULT, looking for mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
2020-07-30 21:36:22.108698+0300 Test-MonoIos[17012:7664742] Mono: Assembly Ref addref System.Core[0x280c47300] -> mscorlib[0x280c4f000]: 4
2020-07-30 21:36:22.134585+0300 Test-MonoIos[17012:7664742] Mono: Image addref Test-MonoIos[0x280c4f700] (asmctx DEFAULT) -> .mono/assemblies/Debug/Test-MonoIos.dll[0x10f147c00]: 2
2020-07-30 21:36:22.134607+0300 Test-MonoIos[17012:7664742] Mono: Prepared to set up assembly 'Test-MonoIos' (.mono/assemblies/Debug/Test-MonoIos.dll)
2020-07-30 21:36:22.134616+0300 Test-MonoIos[17012:7664742] Mono: Assembly Test-MonoIos[0x280c4f700] added to domain GodotEngine.RootDomain, ref_count=1
2020-07-30 21:36:22.134625+0300 Test-MonoIos[17012:7664742] Mono: Found statically linked AOT module 'Test-MonoIos'.
2020-07-30 21:36:22.135241+0300 Test-MonoIos[17012:7664742] Mono: AOT: image 'Test-MonoIos' found.
2020-07-30 21:36:22.253087+0300 Test-MonoIos[17012:7664742] Mono: Loading reference 1 of .mono/assemblies/Debug/Test-MonoIos.dll asmctx DEFAULT, looking for GodotSharp, Version=1.0.7482.13981, Culture=neutral, PublicKeyToken=null
2020-07-30 21:36:22.253119+0300 Test-MonoIos[17012:7664742] Mono: Assembly Ref addref Test-MonoIos[0x280c4f700] -> GodotSharp[0x280c46d00]: 2
2020-07-30 21:36:22.255647+0300 Test-MonoIos[17012:7664742] Mono: Loading reference 0 of .mono/assemblies/Debug/Test-MonoIos.dll asmctx DEFAULT, looking for mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
2020-07-30 21:36:22.255663+0300 Test-MonoIos[17012:7664742] Mono: Assembly Ref addref Test-MonoIos[0x280c4f700] -> mscorlib[0x280c4f000]: 5
2020-07-30 21:36:22.272652+0300 Test-MonoIos[17012:7664742] Mono: Loading reference 0 of .mono/assemblies/Debug/Mono.Security.dll asmctx DEFAULT, looking for mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
2020-07-30 21:36:22.272680+0300 Test-MonoIos[17012:7664742] Mono: Assembly Ref addref Mono.Security[0x280c47100] -> mscorlib[0x280c4f000]: 6

@neikeq
Copy link
Contributor

neikeq commented Aug 3, 2020

This looks similar to #38810, but a part of the exception message seems to be missing in your error message.
I tested today both with 3.2.3 RC3 and a custom build and couldn't reproduce this.
Are you running the app directly from Xcode or do you archive it for deployment?

The error suggests these symbols are being stripped by the linker.
Right now we're using -rdynamic as a workaround until we do this properly by finding all DllImports and passing them to the linker as undefined symbols with -u symbol as described here:

// Force load and export dynamic are needed for the linker to not strip required symbols.
// In theory we shouldn't be relying on this for P/Invoked functions (as is the case with
// functions in System.Native/libmono-native). Instead, we should use cecil to search for
// DllImports in assemblies and pass them to 'ld' as '-u/--undefined {pinvoke_symbol}'.
exporter.AddIosLinkerFlags("-rdynamic");
exporter.AddIosLinkerFlags($"-force_load \"$(SRCROOT)/{MonoLibFile("libmono-native")}\"");

I don't know if this is the reason it isn't working for some people. You could try adding -u _SystemNative_Stat2 to Other Linker Flags in Xcode and check if that fixes it or if the symbol in the exception is a different one.

Well, I have a mono that got installed with Xamarin, but it's hardly relevant

Is it not? My understanding is that the Mono assemblies that get bundled with your app (including System and mscorlib) are the ones from your local Mono distribution.

No, the official Godot builds bundle their own Mono assemblies in the export templates. The Mono distribution in your system should have no effect on exported games.

@andy-noisyduck
Copy link
Contributor Author

andy-noisyduck commented Aug 4, 2020

I don't know if this is the reason it isn't working for some people. You could try adding -u _SystemNative_Stat2 to Other Linker Flags in Xcode and check if that fixes it or if the symbol in the exception is a different one.

I get the same exception with the extra linker params.

Are you running the app directly from Xcode or do you archive it for deployment?

This is when archiving for deployment. I sign the app for Ad-Hoc then run on the appropriate device.

part of the exception message seems to be missing in your error message.

That is genuinely the exception message. It just says SystemNative_Stat2 without further information. I'm dumping ex.Message and ex.StackTrace and that's all I get. It's not the most helpful of outputs.

@neikeq
Copy link
Contributor

neikeq commented May 16, 2021

This week I was finally able to give this a try (I got an M1 last year but couldn't get my builds working until now) and I managed to reproduce the issue.
I can confirm passing -u to the linker correctly makes it not strip the symbol, fixing the issue. However it has to be done this way:

  • The linker flags are of the form: -Wl,-u,_SystemNative_Stat2
  • These linker flags have to be added to the Other Linker Flags build setting for the TARGET, not the PROJECT.

So in order to fix the issue what I need to do is:

  1. Use cecil or reflection to collect a list of all DllImports in the compiled assemblies to determine which symbols need to be kept.
  2. Modify the exporter to allow specifying linker flags for the target instead of the project.

@neikeq
Copy link
Contributor

neikeq commented May 21, 2021

If any one wants to test, the fixes can be found in this branch, but they cannot be merged yet until #45480 is added back (it was temporarily reverted) and #45499 is merged. My branch has those two PRs cherry-picked for testing.

@Difference
Copy link

I don't know if this is relevant, but I have an iOS app that only crashes in Achived-> Ad Hoc mode, so it will run on my devices, but not pass Apple review. It seems the reason is it's using C#'s native Random . I'm swapping it out for GD.Random, and that fixes the problem.

@neikeq
Copy link
Contributor

neikeq commented Jun 12, 2021

Fixed by #49248.

@Difference That should be the same issue, so it should be fixed in the next release.

@neikeq neikeq closed this as completed Jun 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants