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

Fix mkbundle executable crash #3767

Merged
merged 3 commits into from
Feb 18, 2023
Merged

Fix mkbundle executable crash #3767

merged 3 commits into from
Feb 18, 2023

Conversation

memchr
Copy link
Contributor

@memchr memchr commented Jan 20, 2023

In CKAN.GameInstance.PortableDir (CKAN.Games.IGame game):

            // Find the directory our executable is stored in.
            string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

An empty string would be assigned to exeDir when ckan is packaged
using mkbundle. This caused following method call
game.GameInFolder(new DirectoryInfo(exeDir)) to crash with
System.ArgumentException: The specified path is not of a legal form (empty).

mkbundle --deps -o ckan --simple --machine-config /etc/mono/4.5/machine.config --config /etc/mono/config --simple ckan.exe

In `CKAN.GameInstance.PortableDir (CKAN.Games.IGame game)`:
```cs
            // Find the directory our executable is stored in.
            string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
````
An empty string would be assigned to `exeDir` when ckan is packaged
using mkbundle. This caused following method call
`game.GameInFolder(new DirectoryInfo(exeDir))` to crash with
`System.ArgumentException: The specified path is not of a legal form (empty).`
Core/GameInstance.cs Outdated Show resolved Hide resolved
@HebaruSan
Copy link
Member

For anyone else who wasn't familiar with mkbundle, it generates "self-contained executables that do not rely on Mono being installed on the system to simplify deployment of .NET Applications":

That sounds potentially useful as an alternate download format. Though for this specific fix, it would be better if we could fall back to the path of the mkbundle-generated executable when the executing assembly path can't be found, so users could still put their native-compiled ckan executable in the game root.

@memchr, would you mind checking the size of the executables generated in this way? I'm not currently in a Mono environment.

Co-authored-by: HebaruSan <[email protected]>
@HebaruSan
Copy link
Member

HebaruSan commented Feb 18, 2023

This might be the way to get the bundle path:

Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName)

EDIT: Confirmed, with this change I am able to place the native ckan executable in a game folder and the portable instance is detected. Commit pushed.

@HebaruSan HebaruSan added Bug Something is not working as intended Easy This is easy to fix Core (ckan.dll) Issues affecting the core part of CKAN Pull request Linux Issues specific for Linux Mono Issues specific for Mono labels Feb 18, 2023
@memchr
Copy link
Contributor Author

memchr commented Feb 18, 2023

would you mind checking the size of the executables generated in this way? I'm not currently in a Mono environment.

Size of executable generated with mono 6.12.0.177 on Linux is 36.1 MB

@HebaruSan
Copy link
Member

Thanks! That's surprisingly reasonable compared to other modern day downloads (even if it's much larger than ckan.exe by itself). Bigger than Python, smaller than VLC or Git. This might make a nice middle ground between the current downloads and the full-on bloat packaging requested in #2636.

@HebaruSan
Copy link
Member

What command line are you using to build? My Ubuntu VM is giving me an error related to I18N.dll, but if you've already got it building enough to crash, maybe you already know the solution to this?

$ mkbundle --deps ckan.exe
Failure to load i18n assemblies, the following directories were searched for the assemblies:
   Path: .
In Custom mode, you need to provide the directory to lookup assemblies from using -L
ERROR: Couldn't load one or more of the i18n assemblies: Failed to load I18N.dll

@memchr
Copy link
Contributor Author

memchr commented Feb 18, 2023

The command i am using is:

mkbundle --deps -o ckan --simple --machine-config /etc/mono/4.5/machine.config --config /etc/mono/config --simple ckan.exe

However this may not work on Ubuntu as I only tested it on Arch.
You may need to change path of --machine-config and --config

@memchr memchr closed this Feb 18, 2023
@memchr memchr reopened this Feb 18, 2023
@HebaruSan
Copy link
Member

Thanks, that also worked on Ubuntu. 🎉

Copy link
Member

@HebaruSan HebaruSan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for improving compatibility with mkbundle!

@HebaruSan HebaruSan merged commit 8390a61 into KSP-CKAN:master Feb 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN Easy This is easy to fix Linux Issues specific for Linux Mono Issues specific for Mono
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants