After going through the convoluted process of getting an app notarised so it can run on Mac OS X 10.15 Catalina, a problem popped up for some people:
System.TypeInitializationException: The type initializer for 'Keyboard' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Sdl' threw an exception. ---> System.DllNotFoundException: libdl.so.2 at (wrapper managed-to-native) MonoGame.Utilities.FuncLoader+Linux.dlopen(string,int)
As you can see "Linux.dlopen" was being called and not the Mac function.
Lots of delving later I discovered the problem to be in CurrentPlatform.cs, in the DLLImport call for uname:
[DllImport ("libc")]
static extern int uname(IntPtr buf);
The call to uname was causing a dll not found crash. The full path needs to be specified for Macs to cover this problem.
Note I could not reproduce this problem but many of my customers could. I believe its connected to the fact that you have to do a hardened codesign and codesign the individual dylib libraries also in the MonoBundle part of the application.
I used the following to fix the code and keep it working for Linux also.
Replace the DllImport call with:
[DllImport ("libc", EntryPoint="uname")]
static extern int unameNoPath(IntPtr buf);
[DllImport ("/usr/lib/libc", EntryPoint="uname")]
static extern int unameWithPath(IntPtr buf);
and the uname() call with:
int unameResult;
try {
unameResult = unameNoPath (buf);
} catch {
unameResult = unameWithPath (buf);
}
if (unameResult == 0) {
There is also a bug in the file just after the uname() call - the return needs to be removed after the line
and instead add a check before the switch break:
if (os == OS.MacOSX)
break;
os = OS.Linux;
break;
What version of MonoGame does the bug occur on:
What operating system are you using:
What MonoGame platform are you using:
After going through the convoluted process of getting an app notarised so it can run on Mac OS X 10.15 Catalina, a problem popped up for some people:
As you can see "Linux.dlopen" was being called and not the Mac function.
Lots of delving later I discovered the problem to be in CurrentPlatform.cs, in the DLLImport call for uname:
The call to uname was causing a dll not found crash. The full path needs to be specified for Macs to cover this problem.
Note I could not reproduce this problem but many of my customers could. I believe its connected to the fact that you have to do a hardened codesign and codesign the individual dylib libraries also in the MonoBundle part of the application.
I used the following to fix the code and keep it working for Linux also.
Replace the DllImport call with:
and the uname() call with:
There is also a bug in the file just after the uname() call - the return needs to be removed after the line
and instead add a check before the switch break:
What version of MonoGame does the bug occur on:
What operating system are you using:
What MonoGame platform are you using: