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 platform checks and crash on Mac OS X #2600

Merged
merged 1 commit into from
Dec 12, 2018

Conversation

HebaruSan
Copy link
Member

Problem

Mac clients are failing currently:

System.DllNotFoundException: libX11.dylib
  at (wrapper managed-to-native) CKAN.X11.XSetClassHint(intptr,intptr,intptr)
  at CKAN.X11.SetWMClass (System.String name, System.String wmClass, System.IntPtr handle) [0x0004c] in <2c2371fb3f2949b2a6dfae930758e6ee>:0 
  at CKAN.Main.<.ctor>b__37_5 (System.Object sender, System.EventArgs e) [0x00010] in <2c2371fb3f2949b2a6dfae930758e6ee>:0 
  at (wrapper delegate-invoke) <Module>.invoke_void_object_EventArgs(object,System.EventArgs)
  at System.Windows.Forms.Control.OnHandleCreated (System.EventArgs e) [0x00019] in <7cb6368c5ba549ff8a02965fd9de701e>:0 
  at System.Windows.Forms.Form.OnHandleCreated (System.EventArgs e) [0x00016] in <7cb6368c5ba549ff8a02965fd9de701e>:0 
  at System.Windows.Forms.Control.WmCreate (System.Windows.Forms.Message& m) [0x00000] in <7cb6368c5ba549ff8a02965fd9de701e>:0 
  at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message& m) [0x0021c] in <7cb6368c5ba549ff8a02965fd9de701e>:0 
  at System.Windows.Forms.ScrollableControl.WndProc (System.Windows.Forms.Message& m) [0x00000] in <7cb6368c5ba549ff8a02965fd9de701e>:0 
  at System.Windows.Forms.ContainerControl.WndProc (System.Windows.Forms.Message& m) [0x00029] in <7cb6368c5ba549ff8a02965fd9de701e>:0 
  at System.Windows.Forms.Form.WndProc (System.Windows.Forms.Message& m) [0x00166] in <7cb6368c5ba549ff8a02965fd9de701e>:0 
  at System.Windows.Forms.Control+ControlWindowTarget.OnMessage (System.Windows.Forms.Message& m) [0x00000] in <7cb6368c5ba549ff8a02965fd9de701e>:0 
  at System.Windows.Forms.Control+ControlNativeWindow.WndProc (System.Windows.Forms.Message& m) [0x0000b] in <7cb6368c5ba549ff8a02965fd9de701e>:0 
  at System.Windows.Forms.NativeWindow.WndProc (System.IntPtr hWnd, System.Windows.Forms.Msg msg, System.IntPtr wParam, System.IntPtr lParam) [0x00085] in <7cb6368c5ba549ff8a02965fd9de701e>:0 
1926 [1] ERROR CKAN.URLHandlers (null) - There was an error while registering the URL handler for ckan:// - Could not find a part of the path "/Users/teamgros/.local/share/applications/mimeapps.list".
1936 [1] ERROR CKAN.URLHandlers (null) -   at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x00164] in <14f1e720d53a4a6a8800252bec102319>:0 
  at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.IO.FileOptions options, System.String msgPath, System.Boolean bFromProxy, System.Boolean useLongPath, System.Boolean checkHost) [0x00000] in <14f1e720d53a4a6a8800252bec102319>:0 
  at (wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,int,System.IO.FileOptions,string,bool,bool,bool)
  at System.IO.StreamWriter.CreateFile (System.String path, System.Boolean append, System.Boolean checkHost) [0x0001c] in <14f1e720d53a4a6a8800252bec102319>:0 
  at System.IO.StreamWriter..ctor (System.String path, System.Boolean append, System.Text.Encoding encoding, System.Int32 bufferSize, System.Boolean checkHost) [0x00055] in <14f1e720d53a4a6a8800252bec102319>:0 
  at System.IO.StreamWriter..ctor (System.String path, System.Boolean append, System.Text.Encoding encoding, System.Int32 bufferSize) [0x00000] in <14f1e720d53a4a6a8800252bec102319>:0 
  at System.IO.StreamWriter..ctor (System.String path) [0x00008] in <14f1e720d53a4a6a8800252bec102319>:0 
  at (wrapper remoting-invoke-with-check) System.IO.StreamWriter..ctor(string)
  at System.IO.File.WriteAllLines (System.String path, System.String[] contents) [0x00000] in <14f1e720d53a4a6a8800252bec102319>:0 
  at CKAN.URLHandlers.RegisterURLHandler_Linux () [0x00050] in <2c2371fb3f2949b2a6dfae930758e6ee>:0 
  at CKAN.URLHandlers.RegisterURLHandler (CKAN.Configuration config, CKAN.IUser user) [0x00007] in <2c2371fb3f2949b2a6dfae930758e6ee>:0 
Terminated: 15

Cause

#2586 added some X11-specific code to set the window name. We use Platform.IsUnix to determine whether to run it:

CKAN/GUI/Main.cs

Lines 263 to 267 in 7413c23

// Set the window name and class for X11
if (Platform.IsUnix)
{
HandleCreated += (sender, e) => X11.SetWMClass("CKAN", "CKAN", Handle);
}

Platform.IsUnix's documentation says "but not Mac":

CKAN/Core/Platform.cs

Lines 60 to 67 in 7413c23

/// <summary>
/// Are we on a Unix (including Linux, but *not* Mac) system.
/// </summary>
/// <value><c>true</c> if is unix; otherwise, <c>false</c>.</value>
public static bool IsUnix
{
get { return Environment.OSVersion.Platform == PlatformID.Unix; }
}

However, this is false; IsUnix is true on Mac, because Environment.OSVersion.Platform has the same value on both.
https://docs.microsoft.com/en-us/dotnet/api/system.platformid?view=netframework-4.7.2

Notably, this causes the wrong code to run on Macs in other places:

var configuration = new Configuration
{
path = path,
CommandLineArguments = Platform.IsUnix ? "./KSP.x86_64 -single-instance" :
Platform.IsMac ? "./KSP.app/Contents/MacOS/KSP" :
"KSP_x64.exe -single-instance"
};

CKAN/GUI/URLHandlers.cs

Lines 36 to 39 in 7413c23

if (Platform.IsUnix)
{
RegisterURLHandler_Linux();
}

Changes

Now Platform.IsUnix is false on Mac, as per the documentation. This will prevent that code from running on Mac, and might also prevent some problems with those Configuration and URLHandler snippets.

Now the X11-specific code from #2586 is governed by a new Platform.IsX11 value, which is only true if you're on Unix and the $DISPLAY environment variable is defined. Maybe this will help if you have Wayland.

Now even if you somehow manage to execute the XSetClassHint statement on a system that doesn't support it, the DllNotFoundException exception is simply ignored, because its failure is of no importance.

Fixes #2595.

@HebaruSan HebaruSan added Bug Something is not working as intended Pull request macOS Issues specific for macOS labels Dec 4, 2018
@cranehawk
Copy link

Have this issue too. Thank you.

@GabrielHogan
Copy link

How do I use this?

@DasSkelett
Copy link
Member

The fix is not deployed yet @GabrielHogan

@GabrielHogan
Copy link

Is there any way for me to fix & compile this myself?

@DasSkelett
Copy link
Member

DasSkelett commented Dec 11, 2018

(Link removed, get https://github.com/KSP-CKAN/CKAN/releases/latest)
Should work for you.
I compiled that from this (HebaruSan:fix/platform-checks) branch.

@GabrielHogan
Copy link

Thank You!

@AlexCharyna
Copy link

Thank you! This worked for me as well!

@politas politas merged commit b1ffd21 into KSP-CKAN:master Dec 12, 2018
@HebaruSan HebaruSan deleted the fix/platform-checks branch December 12, 2018 16:19
@maxthrustau
Copy link

hi, I am creator of issue #2612 . When I tried the fix it didn't work on my computer.
halp

@HebaruSan
Copy link
Member Author

@maxthrustau, can you add a stack trace to your issue? If it's really a different problem we can re-open it for investigation.

@maxthrustau
Copy link

stack trace?

@maxthrustau
Copy link

what's that? (sorry I do not have a computer background)

@HebaruSan
Copy link
Member Author

Hmm, how did you test the fix?

@maxthrustau
Copy link

I tried it out in place of the old ckan file

@HebaruSan
Copy link
Member Author

Meaning what? You double clicked on the EXE file?

@maxthrustau
Copy link

no I ran it through terminal with mono --arch=32 ckan.exe

@HebaruSan
Copy link
Member Author

OK, good. Did it print anything in the terminal? Usually that's where the stack trace would appear.

@maxthrustau
Copy link

Umm yeah my terminal blurted out a large amount of code before the terminal froze

@HebaruSan
Copy link
Member Author

OK, if you can copy paste that text into your issue there's a chance we can fix it.

@maxthrustau
Copy link

do u want all the code because it took me 4 minutes to copy and paste

@HebaruSan
Copy link
Member Author

Whatever you can manage to grab, lay it on us: #2612

@maxthrustau
Copy link

umm, I can't type it all in because my comment is too long

@HebaruSan
Copy link
Member Author

Whatever you can manage to grab, lay it on us: #2612

@RichieGrahamRichie2k3
Copy link

RichieGrahamRichie2k3 commented Feb 19, 2019

(Link removed, get https://github.com/KSP-CKAN/CKAN/releases/latest)
Should work for you.
I compiled that from this (HebaruSan:fix/platform-checks) branch.

Hey! @DasSkelett

Any chance you could do the same with the osx file for us poor mac users? there's an issue in #2595 that's fixed here (i think) -- it causes ckan to crash on startup so the latest release is unusable on OSX at the moment as far as I'm aware!

Cheers!!

Richie

@DasSkelett
Copy link
Member

Do you mean the CKAN.dmg with 'osx file'?
Unfortunately I can't compile that one. But you should be able to use the .exe I provided in the zip with mono on OSX.
I have compiled it from this branch, so the fix for #2595 is included.

Also I think a new CKAN release is around the corner, but @politas knows more about this.

@HebaruSan
Copy link
Member Author

@DasSkelett , you probably can build it if you have a working Linux system...

cd macosx
make

Look for the dmg file in _build/osx.

@RichieGrahamRichie2k3
Copy link

Do you mean the CKAN.dmg with 'osx file'?
Unfortunately I can't compile that one. But you should be able to use the .exe I provided in the zip with mono on OSX.
I have compiled it from this branch, so the fix for #2595 is included.

Also I think a new CKAN release is around the corner, but @politas knows more about this.

Yeah, that's the one sorry! - no problem I can use the .exe with mono as you said :)

Also worth noting to other OSX users that you can delete the GUIConfig.xml file from the /ckan directory and re-run cKan which will 'fix' the issue for that load and it doesn't delete your installed mod's etc if you want to stay on the current release but need a 'quick fix'

Cheers Both!!

@DasSkelett
Copy link
Member

DasSkelett commented Feb 19, 2019

Oh okay, never knew that, thanks @HebaruSan
Worked on the third try, you need two additional packages ;)

@RichieGrahamRichie2k3, (Link removed, get https://github.com/KSP-CKAN/CKAN/releases/latest) contains the .dmg compiled from the current master branch HEAD (62da77d).
This one is already registered as "v1.26.0", so make sure to check for the official 1.26 release on the release page regularly, because CKAN won't be able to detect it itself.

@RichieGrahamRichie2k3
Copy link

@DasSkelett - just tried it, works perfectly and no need to delete GUIConfig.xml each time

Thank you!!

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 macOS Issues specific for macOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CKAN crashing on startup MacOS
8 participants