roice3 / MagicTile

Non-euclidean Rubik's Cube Analogues
http://www.gravitation3d.com/magictile
MIT License
86 stars 12 forks source link

Mono support #7

Closed jhidding closed 6 years ago

jhidding commented 7 years ago

Hi, I saw Mathologgers video and wanted to give this program a shot under Linux/Mono. I first tried with the binary download from the website. I'm running on Debian testing with Mono 4.2 and OpenTK 1.1.4 installed. The program gives the following messages:

MainForm initialized.
Menus built.
Failed to load settings.
Could not find file "/home/johannes/.config/MagicTile v2/settings.xml".
ExceptionHandler caught: Object reference not set to an instance of an object
^C

The window never appears. I tried compiling from source, which kind of worked (with many warnings), but the resulting binary gives the same error. I'm not a C#/.NET programmer so I'm not sure how to proceed. Cheers!

roice3 commented 7 years ago

Cool, you are the first I know to attempt this, so I'm not surprised at all there are problems. Thanks for giving it a shot!

I checked the code loading the settings, which is here.

I'm guessing the DataContractSerializer in Mono doesn't like it if the file does not exist, even though it is perfectly happy with that in Windows. You could try adding this line above the LoadFromXml call:

if( !System.IO.File.Exists( StandardPaths.SettingsFile ) )
    return new Settings();

I suspect this is the first of lots more problems though :/

noughtmare commented 7 years ago

Your fix seems to work, but now there is another error:

ExceptionHandler caught: Object reference not set to an instance of an object

I've debugged it and it seems this line seems to cause the error:

object propertyGridView = gridViewFieldInfo.GetValue( grid );

In SetLabelColumnWidth in MainForm.cs.

Edit: This line sets gridViewFieldInfo to null:

FieldInfo gridViewFieldInfo = typeof( PropertyGrid ).GetField( "gridView",
                BindingFlags.Instance | BindingFlags.NonPublic );
roice3 commented 7 years ago

Yep, I think for this (and the many other issues that are bound to arise), removing any unnecessary code would be a good approach. In this case, this function is setting the PropertyGrid columns widths to something other than the default. In terms of getting things going in Mono, I'd just completely remove the call to the SetLabelColumnWidth function myself.

noughtmare commented 7 years ago

Removing that call works, but now the program just exits after it reaches Application.Run( form );.

noughtmare commented 7 years ago

Here's what the form object looks like just before Application.Run(form): https://gist.github.com/noughtmare/a362d444180330418ec9b2f118cecf2a

PS: I don't know if this is helpful, I'm also not a C# programmer.

roice3 commented 7 years ago

This is where I run away and hide for cover :) Sorry.

Like I've been saying, I suspect a Mono port is going to be non trivial.

noughtmare commented 7 years ago

I have compiled opentk from source and added it as a .net assembly reference and now it works!

jhidding commented 7 years ago

I pulled from @remuladgryta fork, and this works now!

mjg123 commented 7 years ago

This makes me very happy 👍 Are the instructions on how to build from that fork, or binaries anywhere? I know next-to-nothing about the mono buildchain.

jhidding commented 7 years ago

The patch fixes some references for .NET 4.5, and the OpenTK library. I can imagine this would in turn break building it on MSVC. To build with mono, just run xbuild in the project root folder. The binary appears in ./MagicTile/bin/Debug.

mjg123 commented 7 years ago

I've compiled the OpenTK dependency locally, but still get

"/usr/local/Cellar/mono/4.6.0.245/lib/mono/xbuild/14.0/bin/Microsoft.Common.targets:  warning : Reference 'OpenTK' not resolved"

then lots of compilation errors (this is macos, btw).

I guess this might be to do with the HintPaths in here https://github.com/remuladgryta/MagicTile/blob/master/MagicTile/MagicTile.csproj#L66-L71 pointing to the wrong place? But even using absolute paths to the compiled dlls in the opentk distribution, I get the same errors.

jhidding commented 7 years ago

I don't have this issue since the OpenTk provided by the systems package manager in Debian works fine, but I believe setting MONO_PATH to the correct assemblies path should work.

mjg123 commented 7 years ago

Ah ha! The trick is to read the list of places that the build tools are looking for the DLLs, and just copy them into there. Up and running now. FWIW this is the complete set of things I had to do on MacOS:

1/ Install wine, instructions: https://www.davidbaumgold.com/tutorials/wine-mac/ 2/ Clone & build opentk, instructions: https://github.com/opentk/opentk#instructions 3/ Install xbuild: brew install mono 4/ Clone the forked repo: https://github.com/remuladgryta/MagicTile/ 5/ cd into the MagicTile repo, and try to build: xbuild MagicTile.sln 6/ Look for error messages in the output like: Considered './MagicTile/R3/R3.Core/bin/Debug/OpenTK.dll' as a file, but the file does not exist 7/ Copy the files built in step 2 into the places that xbuild is looking. There are 2 dlls, OpenTK.dll and OpenTK.GLControl.dll. Re-run the xbuild command until it works ;) 8/ cd MagicTile && wine ./bin/Debug/MagicTile.exe 8.6/ TODO: Not all the puzzles load correctly. 9/ ... 🎉 MAGIC 🎉

noughtmare commented 7 years ago

@mjg123 if you install mono you shouldn't have to install wine, you could probably just run mono ./MagicTile/bin/Debug/MagicTile.exe in step 8.

mjg123 commented 7 years ago

That doesn't quite work for me 😢 (but I'm not an expert in wine, mono or macos)

MagicTile|master⚡ ⇒ mono MagicTile/bin/Debug/MagicTile.exe
WARNING: The Carbon driver has not been ported to 64bits, and very few parts of Windows.Forms will work properly, or at all
ExceptionHandler caught: The type initializer for 'System.Windows.Forms.WindowsFormsSynchronizationContext' threw an exception.
Inner exception was: The type initializer for 'System.Windows.Forms.ThemeEngine' threw an exception.
noughtmare commented 7 years ago

Maybe you have to install a 32bit version of mono, I think that is included in wine so that's probably easier.

roice3 commented 7 years ago

This is great, you guys are awesome.

Now I'm wondering if we should try to get a decent Release build for Mono and include it as an additional download on the site. I've had a lot of folks ask about running MagicTile on Mac over the years, and it'd be cool to provide them a path (other than telling them to run an emulated Windows machine).

remuladgryta commented 7 years ago

I tried compiling MagicTile on a whim after seeing the mathologer video. I'm not very experienced with C# development, but it only took a couple of hours to get working. It's nice to see someone appreciate it!

To get it to build, all I really did was open the project in monodevelop, and change the target framework in the project settings to one of the available ones. The majority of the time I spent was on googling C# syntax in order to track down the PropertyGrid issue and just disable the method.

I don't have access to a mac so I can't test it, but I would guess that using the osx version of monodevelop to fix the build dependencies is all that's needed to get my fork working on mac.

hyiltiz commented 7 years ago

This is exciting! Once OSX is running, Linux is just one step away! I'll try the above method, and see if I can let it work in my OSX and Linux (Debian).

The method above for OSX doesn't work on my OSX Sierra. With a few changes, it worked. Specifically, I had to fork and build https://github.com/mono/libgdiplus, though it had to be part of mono, which required some other libraries as dependencies including libpng12. I installed it through brew, and tried to create symlink to various places (/usr/loca/lib, /usr/X11/lib, ./) etc to build libgdiplus, but all attempts failed to find libpng12 to build libgdiplus.

$ xbuild MagicTile.sln
XBuild Engine Version 14.0
Mono, Version 4.6.1.0
Copyright (C) 2005-2013 Various Mono authors

Build started 10/28/2016 3:25:38 PM.
__________________________________________________
Project "/Users/hyiltiz/Documents/Github/MagicTile/MagicTile.sln" (default target(s)):
    Target ValidateSolutionConfiguration:
        Building solution configuration "Debug|Mixed Platforms".
    Target Build:
        Project "/Users/hyiltiz/Documents/Github/MagicTile/R3/R3.Core/R3.Core.csproj" (default target(s)):
            Target PrepareForBuild:
                Configuration: Debug Platform: AnyCPU
            Target GenerateSatelliteAssemblies:
            No input files were specified for target GenerateSatelliteAssemblies, skipping.
            Target _GenerateTargetFrameworkMonikerAttribute:
            Skipping target "_GenerateTargetFrameworkMonikerAttribute" because its outputs are up-to-date.
            Target CoreCompile:
            Skipping target "CoreCompile" because its outputs are up-to-date.
        Done building project "/Users/hyiltiz/Documents/Github/MagicTile/R3/R3.Core/R3.Core.csproj".
        Project "/Users/hyiltiz/Documents/Github/MagicTile/MagicTile/MagicTile.csproj" (default target(s)):
            Target PrepareForBuild:
                Configuration: Debug Platform: x86
            Target ResolveAssemblyReferences:
/usr/local/Cellar/mono/4.6.1.5/lib/mono/xbuild/14.0/bin/Microsoft.Common.targets:  warning : Reference 'OpenTK.GLControl, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4' not resolved
                For searchpath {CandidateAssemblyFiles}
                Warning: {CandidateAssemblyFiles} not supported currently
                For searchpath {HintPathFromItem}
                Considered ../OpenTK/Binaries/OpenTK/Release/OpenTK.GLControl.dll, but it does not exist.
                For searchpath {TargetFrameworkDirectory}
                Considered target framework dir /usr/local/Cellar/mono/4.6.1.5/lib/mono/4.5-api/, assembly named 'OpenTK.GLControl' not found.
                Considered target framework dir /usr/local/Cellar/mono/4.6.1.5/lib/mono/4.5-api//Facades/, assembly named 'OpenTK.GLControl' not found.
                For searchpath {PkgConfig}
                Considered OpenTK.GLControl, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, but could not find in any pkg-config files.
                For searchpath {GAC}
                Considered OpenTK.GLControl, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, but could not find in the GAC.
                For searchpath {RawFileName}
                Considered 'OpenTK.GLControl, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4' as a file, but the file does not exist
                For searchpath bin/Debug/
                Considered '/Users/hyiltiz/Documents/Github/MagicTile/MagicTile/bin/Debug/OpenTK.GLControl' as a file, but the file does not exist
                Considered '/Users/hyiltiz/Documents/Github/MagicTile/MagicTile/bin/Debug/OpenTK.GLControl.exe' as a file, but the file does not exist
                Considered '/Users/hyiltiz/Documents/Github/MagicTile/MagicTile/bin/Debug/OpenTK.GLControl.dll' as a file, but the file does not exist
            Target GenerateSatelliteAssemblies:
            No input files were specified for target GenerateSatelliteAssemblies, skipping.
            Target _GenerateTargetFrameworkMonikerAttribute:
            Skipping target "_GenerateTargetFrameworkMonikerAttribute" because its outputs are up-to-date.
            Target CoreCompile:
                Tool /usr/local/Cellar/mono/4.6.1.5/lib/mono/4.5/mcs.exe execution started with arguments: /noconfig /debug:full /debug+ /optimize- /out:obj/x86/Debug/MagicTile.exe /resource:obj/x86/Debug/MagicTile.EnterStringDlg.resources /resource:obj/x86/Debug/MagicTile.MainForm.resources /resource:obj/x86/Debug/MagicTile.Properties.Resources.resources Control/MouseMotion.cs EnterStringDlg.cs EnterStringDlg.Designer.cs MainForm.cs MainForm.Designer.cs Puzzle/Loader.cs Puzzle/PuzzleConfigClass.cs Puzzle/State.cs Puzzle/Sticker.cs Puzzle/TopologyAnalyzer.cs Puzzle/Twisting/Macro.cs Puzzle/Twisting/Pants.cs Puzzle/Twisting/SetupMoves.cs Puzzle/Twisting/SingleTwist.cs Puzzle/Twisting/SliceMask.cs Puzzle/Twisting/TwistData.cs Puzzle/Twisting/TwistHandler.cs Puzzle/Twisting/TwistHistory.cs Utils/Error.cs Utils/GLUtils.cs Utils/MenuBuilder.cs Program.cs Properties/AssemblyInfo.cs Puzzle/Cell.cs Puzzle/Puzzle.cs Puzzle/PuzzleConfig.cs Puzzle/PuzzleRenderer.cs Settings/Settings.cs Utils/DataContractHelper.cs Utils/Sandbox.cs Utils/StandardPaths.cs Utils/Persistence.cs Properties/Resources.Designer.cs Properties/Settings.Designer.cs obj/x86/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs /target:winexe /win32icon:MagicTile.ico /define:"DEBUG;TRACE" /nostdlib /platform:x86 /reference:/usr/local/Cellar/mono/4.6.1.5/lib/mono/4.5-api/System.dll /reference:/usr/local/Cellar/mono/4.6.1.5/lib/mono/4.5-api/System.Numerics.dll /reference:/usr/local/Cellar/mono/4.6.1.5/lib/mono/4.5-api/System.Runtime.Serialization.dll /reference:/usr/local/Cellar/mono/4.6.1.5/lib/mono/4.5-api/System.Xml.Linq.dll /reference:/usr/local/Cellar/mono/4.6.1.5/lib/mono/4.5-api/System.Data.DataSetExtensions.dll /reference:/usr/local/Cellar/mono/4.6.1.5/lib/mono/4.5-api/Microsoft.CSharp.dll /reference:/usr/local/Cellar/mono/4.6.1.5/lib/mono/4.5-api/System.Data.dll /reference:/usr/local/Cellar/mono/4.6.1.5/lib/mono/gac/System.Deployment/4.0.0.0__b03f5f7f11d50a3a/System.Deployment.dll /reference:/usr/local/Cellar/mono/4.6.1.5/lib/mono/4.5-api/System.Drawing.dll /reference:/usr/local/Cellar/mono/4.6.1.5/lib/mono/4.5-api/System.Windows.Forms.dll /reference:/usr/local/Cellar/mono/4.6.1.5/lib/mono/4.5-api/System.Xml.dll /reference:/usr/local/Cellar/mono/4.6.1.5/lib/mono/4.5-api/OpenTK.dll /reference:/usr/local/Cellar/mono/4.6.1.5/lib/mono/4.5-api/System.Core.dll /reference:/Users/hyiltiz/Documents/Github/MagicTile/R3/R3.Core/bin/Debug//R3.Core.dll /reference:/usr/local/Cellar/mono/4.6.1.5/lib/mono/4.5-api//mscorlib.dll /warn:4
MainForm.cs(46,42): error CS0234: The type or namespace name `GLControl' does not exist in the namespace `OpenTK'. Are you missing an assembly reference?
Control/MouseMotion.cs(28,30): error CS0234: The type or namespace name `GLControl' does not exist in the namespace `OpenTK'. Are you missing an assembly reference?
Control/MouseMotion.cs(63,18): error CS0234: The type or namespace name `GLControl' does not exist in the namespace `OpenTK'. Are you missing an assembly reference?
Puzzle/Twisting/TwistHandler.cs(13,24): error CS0246: The type or namespace name `GLControl' could not be found. Are you missing an assembly reference?
Puzzle/Twisting/TwistHandler.cs(41,11): error CS0246: The type or namespace name `GLControl' could not be found. Are you missing an assembly reference?
Puzzle/PuzzleRenderer.cs(19,33): error CS0234: The type or namespace name `GLControl' does not exist in the namespace `OpenTK'. Are you missing an assembly reference?
Puzzle/PuzzleRenderer.cs(46,18): error CS0234: The type or namespace name `GLControl' does not exist in the namespace `OpenTK'. Are you missing an assembly reference?
            Task "Csc" execution -- FAILED
            Done building target "CoreCompile" in project "/Users/hyiltiz/Documents/Github/MagicTile/MagicTile/MagicTile.csproj".-- FAILED
        Done building project "/Users/hyiltiz/Documents/Github/MagicTile/MagicTile/MagicTile.csproj".-- FAILED
    Task "MSBuild" execution -- FAILED
    Done building target "Build" in project "/Users/hyiltiz/Documents/Github/MagicTile/MagicTile.sln".-- FAILED
Done building project "/Users/hyiltiz/Documents/Github/MagicTile/MagicTile.sln".-- FAILED

Build FAILED.

Warnings:

/Users/hyiltiz/Documents/Github/MagicTile/MagicTile.sln (default targets) ->
(Build target) ->
/Users/hyiltiz/Documents/Github/MagicTile/MagicTile/MagicTile.csproj (default targets) ->
/usr/local/Cellar/mono/4.6.1.5/lib/mono/xbuild/14.0/bin/Microsoft.Common.targets (ResolveAssemblyReferences target) ->

    /usr/local/Cellar/mono/4.6.1.5/lib/mono/xbuild/14.0/bin/Microsoft.Common.targets:  warning : Reference 'OpenTK.GLControl, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4' not resolved

Errors:

/Users/hyiltiz/Documents/Github/MagicTile/MagicTile.sln (default targets) ->
(Build target) ->
/Users/hyiltiz/Documents/Github/MagicTile/MagicTile/MagicTile.csproj (default targets) ->
/usr/local/Cellar/mono/4.6.1.5/lib/mono/xbuild/14.0/bin/Microsoft.CSharp.targets (CoreCompile target) ->

    MainForm.cs(46,42): error CS0234: The type or namespace name `GLControl' does not exist in the namespace `OpenTK'. Are you missing an assembly reference?
    Control/MouseMotion.cs(28,30): error CS0234: The type or namespace name `GLControl' does not exist in the namespace `OpenTK'. Are you missing an assembly reference?
    Control/MouseMotion.cs(63,18): error CS0234: The type or namespace name `GLControl' does not exist in the namespace `OpenTK'. Are you missing an assembly reference?
    Puzzle/Twisting/TwistHandler.cs(13,24): error CS0246: The type or namespace name `GLControl' could not be found. Are you missing an assembly reference?
    Puzzle/Twisting/TwistHandler.cs(41,11): error CS0246: The type or namespace name `GLControl' could not be found. Are you missing an assembly reference?
    Puzzle/PuzzleRenderer.cs(19,33): error CS0234: The type or namespace name `GLControl' does not exist in the namespace `OpenTK'. Are you missing an assembly reference?
    Puzzle/PuzzleRenderer.cs(46,18): error CS0234: The type or namespace name `GLControl' does not exist in the namespace `OpenTK'. Are you missing an assembly reference?

     1 Warning(s)
     7 Error(s)

Time Elapsed 00:00:03.5751290
cpeosphoros commented 7 years ago

Hi there, sorry for necroing an old issue (though it's still open) and also if my suggestions seems a bit naive.

That said, wouldn't it be simpler to just provide a pre-made version of settings.xml and copying it into .config/MagicTile v2 ?

Then you could just run $wine MagicTile.exe (in a winetricked box with all needed dependencies)

roice3 commented 7 years ago

I'd be happy to include this if someone sends me a pull request with said settings.xml file and updates to the readme file with instructions. I am not sure if there are code changes that would be required as well. Based on some of the comments above, it seems that might be required.

Immchuck commented 6 years ago

I am new to this whole coding thing.. I really don't know much. I am 12 years old but i do plan on learning Javascript and such one day. I just want to know if any of you have made something work for this. What your saying is not entirely easy to understand for someone like me so i was wondering if you could just guide me through and let me know if you figured something out.. I have mac so i cant use magictile and as i love rubiks cubes in general, i would love to try this. Thanks

roice3 commented 6 years ago

@Immchuck, my wife recently got a mac so using it and the information in this thread, I was able to get a build created and uploaded. I've put the mac download and instructions here:

http://roice3.org/magictile/downloads/mac.htm

It may not work perfectly, but I hope it gets you going.

cpeosphoros commented 6 years ago

Just leaving a reference to #26

Immchuck commented 6 years ago

I have no idea what this means, hoping you can help screen shot 2018-03-29 at 10 06 45 pm I have downloaded it and used all your instructions and typed the command.. Sorry for being such an idiot.

cpeosphoros commented 6 years ago

MagicTile.exe

names are case sensitive

Immchuck commented 6 years ago

I can always trust you!

Immchuck commented 6 years ago

What! It still says the same thing!

roice3 commented 6 years ago

@Immchuck, it’s hard to tell but it looks like you are not running the correct command to get to the directory where MagicTile lives. You don’t want to “cd: MagicTile.exe”. You want to “cd DirectoryPath”. DirectoryPath is where you uncompressed the download.

If you still have issues, please provide details about where you decompressed the file and the exact sequence of Terminals commands you are calling. That will help diagnose.

Immchuck commented 6 years ago

Ok. Ill try that. I appreciate you working with me while i am being very problematic.

Immchuck commented 6 years ago

So i unzipped my MagicTile folder in my downloads and so i have it and so i put in the command "cd /Users/Steve-----/Downloads" and so i'm in my downloads folder, then i type the command "mono --arch=32 MagicTile.exe" And it still says no such file or directory. (The dashes in the cd command is really just me censoring my name so thats nothing i typed in the actual name)

roice3 commented 6 years ago

You are almost there @Immchuck. The program unzips to it's own directory (because it has a number of companion files). Try:

cd /Users/Steve-----/Downloads/MagicTile_3-27-18

I will attempt to make the instructions more clear about this.

Immchuck commented 6 years ago

Great! I will try this. Will i have to repeat these steps each time I open it? I appreciate you doing this for me, roice! Good stuff is happening.... I have faith

Immchuck commented 6 years ago

I did it! Yaaaay! Hopefully i will no longer have to bother you now! Thank you for all of your help through this i greatly appreciate it!

roice3 commented 6 years ago

Sweet, glad you got it working. And thank you for making the request. Feels good to finally support Mac and I needed an extra kick to provide better support.

As for your question about repeating the steps... you do have to run it from Terminals each time, but there are ways to make that more convenient. A google search showed there may be a nice way to do it with applescript. Another option would be to make a bash script, but it'd probably be about as much effort to run the script as to just run the program.

In any case, have fun with the puzzles!

Immchuck commented 6 years ago

Magictile is doing great! It's really fun. One Question: Would this work with any other .exe files i cannot open can i just replace 'MagicTile.exe' With something else or would that take extra commitment?

roice3 commented 6 years ago

Hi @Immchuck, glad to hear that!

Unfortunately, Mono doesn't work on arbitrary .exe files. They have to be specially built so the answer to your question is 'nope'.

To run other Windows programs, your easiest option may be an emulator like Parallels, though that costs money. You can also look into Wine.

Immchuck commented 5 years ago

Uhh so i got a new pc and all that work was for nothing lol

roice3 commented 5 years ago

@Immchuck, not for nothing! I've been wanting to support Macs for a long time and I'm sure there are others who appreciate you pushing me across the finish line :)

Immchuck commented 5 years ago

oh yeah!