Unfortunately, I’ve come across an exception I haven’t been able to fix on the Macbook we’re using for testing.
I’m using the Monogame 3.7 Release.
I’ve tried mkbundling the game with both mono-5.16.0-osx-10.7-x64 and mono-5.16.0-osx-10.7-x64 with the same results. Near as I can tell from the error it’s having trouble loading libSDL2-2.0.0.dylib, which is the Mac-specific replacement for SDL2.dll, but that’s present and accounted for in the same folder as the executable.
What am I missing?
Exception follows:
Last login: Thu Oct 18 08:13:10 on ttys000
/Users/[REDACTED]/Desktop/Species\ ALRE/SpeciesOSX64 ; exit;
admins-MacBook:~ [REDACTED]$ /Users/[REDACTED]/Desktop/Species\
ALRE/SpeciesOSX64 ; exit;
Unhandled Exception:
System.TypeInitializationException: The type initializer for 'Sdl'
threw an exception. ---> System.Exception: Failed to load SDL library.
at Sdl.GetNativeLibrary () [0x00156] in <11a2afe69fa8407e8841850a70a7d30a>:0
at Sdl..cctor () [0x00000] in <11a2afe69fa8407e8841850a70a7d30a>:0
--- End of inner exception stack trace ---
at Microsoft.Xna.Framework.GamePlatform.PlatformCreate
(Microsoft.Xna.Framework.Game game) [0x00001] in
<11a2afe69fa8407e8841850a70a7d30a>:0
at Microsoft.Xna.Framework.Game..ctor () [0x00225] in
<11a2afe69fa8407e8841850a70a7d30a>:0
at SpeciesALRE.Game1..ctor () [0x0011c] in
<31ae773542af4bbaaa3eb6a1d4413be6>:0
at SpeciesALRE.Program.Main (System.String[] args) [0x00001] in
<31ae773542af4bbaaa3eb6a1d4413be6>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException:
The type initializer for 'Sdl' threw an exception. --->
System.Exception: Failed to load SDL library.
at Sdl.GetNativeLibrary () [0x00156] in <11a2afe69fa8407e8841850a70a7d30a>:0
at Sdl..cctor () [0x00000] in <11a2afe69fa8407e8841850a70a7d30a>:0
--- End of inner exception stack trace ---
at Microsoft.Xna.Framework.GamePlatform.PlatformCreate
(Microsoft.Xna.Framework.Game game) [0x00001] in
<11a2afe69fa8407e8841850a70a7d30a>:0
at Microsoft.Xna.Framework.Game..ctor () [0x00225] in
<11a2afe69fa8407e8841850a70a7d30a>:0
at SpeciesALRE.Game1..ctor () [0x0011c] in
<31ae773542af4bbaaa3eb6a1d4413be6>:0
at SpeciesALRE.Program.Main (System.String[] args) [0x00001] in
<31ae773542af4bbaaa3eb6a1d4413be6>:0
logout
[Process completed]
Unfortunately, the fallback routine for this situation is “Welp, all failed, PANIC!!!”. That is the actual comment. Not exactly helpful, but it made me giggle. You get a pass.
So, that means that …
[DllImport("/usr/lib/libSystem.dylib")]
public static extern IntPtr dlopen(string path, int flags);
… is returning IntPtr.Zero where path=Path.Combine(assemblyLocation, “libSDL2-2.0.0.dylib”). I have to assume assembly location is wrong, then. I don’t think libSD2-2.0.0.dylib would be broken or there’d be a lot more uproar.
Assembly location is defined thusly:
var assemblyLocation = Path.GetDirectoryName((new Uri(typeof(Sdl).Assembly.CodeBase)).LocalPath);
Perhaps if I change LocalPath to AbsolutePath? Worth a shot I guess.
I’m assuming typeof(Sdl) is stored in MonoGame.Framework.dll, so it would have to be a reference to the bundled location? Could it be getting typeof(Sdl) from somewhere else somehow? I could reset assemblyLocation to System.Windows.Forms.Application.StartupPath if that’s the case.
Will submit a few different apps for testing and let you know which, if any, work.
@Quasar is this related to my issue on this post? Wondering if sdl library is actually broken as it compiles on a different os version. Any help would be appreciated. Thanks!
How I solved it was to do a search in the Monogame source for “new Uri(typeof” and replace it with System.Reflection.Assembly.GetEntryAssembly().Location where it appears.
@Quasar Thanks a lot for your help! I succeeded compiling it by adding all the .dll files manually in .csproj as @phuoc.tran suggested here, but would love to try your solution too. I just cannot fully compile MonoGame right now due to a non-code-related issue (or can I?).
I have another question—if I understood correctly, does this mean that High Sierra (10,13) and Catalina (10.15) return different values on new Uri() command? Do you happen to know what makes this difference? Assumption/speculation is welcome. Thanks again!