MapStudioProject / Track-Studio

A powerful MK8 map editor for creating and editing track models, objects, paths and animations.
MIT License
75 stars 13 forks source link

Linux support #28

Open InfinaMii opened 3 months ago

InfinaMii commented 3 months ago

Track Studio won't run on Linux (tested on both Fedora and Ubuntu).

Note - the usage docs still say to run dotnet MapStudio.dll, but this file no longer seems to exist. Since every other dll in the project complained about a missing libhostpolicy.so I'm assuming the correct one to run is now TrackStudio.dll However, running it gives me this error:

Error Unhandled exception. System.TypeInitializationException: The type initializer for 'OpenTK.DisplayDevice' threw an exception.
---> System.DllNotFoundException: Unable to load shared library 'gbm' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libgbm: cannot open shared object file: No such file or directory
at OpenTK.Platform.Linux.Gbm.CreateDevice(Int32 fd)
at OpenTK.Platform.Linux.LinuxFactory.SetupDisplay(String gpu, IntPtr& gbm_device, IntPtr& egl_display)
at OpenTK.Platform.Linux.LinuxFactory.CreateDisplay(IntPtr& gbm_device, IntPtr& egl_display)
at OpenTK.Platform.Linux.LinuxFactory.get_gpu_fd()
at OpenTK.Platform.Linux.LinuxFactory.CreateDisplayDeviceDriver()
at OpenTK.DisplayDevice..cctor()
--- End of inner exception stack trace ---
at OpenTK.DisplayDevice.get_Default()
at UIFramework.Framework..ctor(MainWindow window, GraphicsMode gMode, String asssemblyVersion, String name, Int32 width, Int32 height) in C:\projects\track-studio\MapStudio.UI\src\UIFramework\Framework.cs:line 24
at TrackStudio.Program.Main(String[] args) in C:\projects\track-studio\Track Studio\src\Program.cs:line 50
Aborted (core dumped)

I have libgbm installed so presumably Track Studio either can't find it, or similar to .net 5.0 it depends on an older version which is no longer supported.

I also tried installing the dependencies in WINE and running the exe, which gave me:
A fatal error occurred, the required library hostfxr.dll could not be found in [Z:\usr\lib64\dotnet\host\fxr\8 .0.4]
This was easily fixed by copying hostfxr.dll from the dotnet install at ~/.wine/drive-c into the same folder as TrackStudio.exe, however even though the GUI loads and registers when I hover over the buttons, clicking them doesn't create their respective drop-down menus - basically rendering the program unusable.

InfinaMii commented 3 months ago

Update - using the environment variable LD_DEBUG=libs it seems to not like the libgl.so.1.0.0 file in /etc/lib64 and instead is looking for just libgbm.so.

It seems to detect it fine if I either copy the libgbm.so.1.0.0 file into the same directory as TrackStudio.dll, or start it with the environment variable LD_LIBRARY_PATH= and define a custom path to place renamed copies of the libgbm.so.1.0.0 file. It also doesn't like linked versions of the file - it requires them to be direct copies.

After doing this, it then complains about locating libEGL.dll - which also doesn't exist in /usr/lib64. If I copy libEGL.so.1 to the Track Studio directory and rename it to libEGL.dll.so, it will accept it but report that it was unable to find an entry point named 'eglGetDisplay'.

All of this is basically to say that since all of these exceptions were being thrown by OpenTK.DisplayDevice, I'm assuming the version of OpenTK that Track Studio uses is probably outdated, or has other issues making it incompatible with the latest Linux drivers.

InfinaMii commented 3 weeks ago

Tried it again today and it just worked. I'm not sure if there was an update to fedora packages that added support for whatever wasn't working, but it opened fine. It also couldn't find libssl due to Track Studio wanting the older OpenSSL1.0 rather than 1.1, however this was easily fixed by installing an older package (compat-openssl10 on fedora) and as far as I could tell it works fine now however I will keep this issue open until I can test it with another distro.

InfinaMii commented 1 week ago

Tried to export multiple models on Linux, the textures all get exported, but I get the error: kf.kio.core: KFileFilter::fromMimeType() called with unknown MIME type "Studio/TreeSph.dae" I'm assuming this is a split file path when trying to execute a command? Because "Track Studio" has a space in it, it's read "Documents/Track" or whatever as the first argument (probably file path) and "Studio/TreeSph.dae" as an additional argument, presumably the mimetype. I also had to manually install a package that included the mimeopen command, otherwise it'd just crash when I hit the export button.

EDIT: forgot to try the obvious "rename the track studio folder to have no space". After doing so it works again in the version I have installed (making this a minor oversight), however using the latest version of Track Studio it once again crashes and I get these errors: kf.kio.core.connection: Socket not connected QLocalSocket::PeerClosedError kf.kio.core: An error occurred during write. The worker terminates now. Segmentation fault (core dumped)

InfinaMii commented 4 days ago

I saw linux-related commits, so decided to give the latest version a try. Exporting a model works fine, but none of the textures get exported with it. When trying to "Export All Textures", it opens the destination folder but no textures get exported. If I try to expand the Textures folder, Track Studio crashes with the error:

Error Unhandled exception. System.TypeInitializationException: The type initializer for 'DirectXTexNet.TexHelper' threw an exception. ---> System.BadImageFormatException: Could not load file or assembly '/home/infina/Downloads/net8.0/x64/DirectXTexNetImpl.dll'. An attempt was made to load a program with an incorrect format. File name: '/home/infina/Downloads/net8.0/x64/DirectXTexNetImpl.dll' at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyBinder, String ilPath, String niPath, ObjectHandleOnStack retAssembly) at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath) at System.Reflection.Assembly.LoadFile(String path) at DirectXTexNet.TexHelper..cctor() --- End of inner exception stack trace --- at DirectXTexLibrary.TextureDecoder.DecompressBlock(Byte[] data, Int32 width, Int32 height, DXGI_FORMAT format) in C:\projects\track-studio\Plugins\DirectXTexLibrary\TextureDecoder.cs:line 104 at DirectXTexLibrary.TextureDecoder.Decode(TexFormat format, Byte[] input, Int32 width, Int32 height, Byte[]& output) in C:\projects\track-studio\Plugins\DirectXTexLibrary\TextureDecoder.cs:line 22 at Toolbox.Core.STGenericTexture.DecodeBlock(Byte[] data, UInt32 width, UInt32 height, TexFormat format) in C:\projects\track-studio\Toolbox.Core\src\Generic\Texture\STGenericTexture.cs:line 377 at Toolbox.Core.STGenericTexture.GetDecodedSurface(Int32 ArrayLevel, Int32 MipLevel, Int32 DepthLevel) in C:\projects\track-studio\Toolbox.Core\src\Generic\Texture\STGenericTexture.cs:line 358 at GLFrameworkEngine.GLTexture.g__PushImageData|70_0(Byte[] surface, Int32 mipLevel, Int32 depthLevel, <>c__DisplayClass70_0&) in C:\projects\track-studio\GLFrameworkEngine\Objects\Texture\GLTexture.cs:line 184 at GLFrameworkEngine.GLTexture.LoadImage(STGenericTexture texture, ImageParameters parameters) in C:\projects\track-studio\GLFrameworkEngine\Objects\Texture\GLTexture.cs:line 222 at GLFrameworkEngine.GLTexture2D.FromGeneric(STGenericTexture texture, ImageParameters parameters) in C:\projects\track-studio\GLFrameworkEngine\Objects\Texture\GLTexture2D.cs:line 231 at MapStudio.UI.IconRender.CreateTextureRender(STGenericTexture texture, Int32 width, Int32 height, Boolean displayAlpha) in C:\projects\track-studio\MapStudio.UI\src\Icons\IconRender.cs:line 55 at MapStudio.UI.IconManager.DrawTexture(String key, STGenericTexture texture, Int32 width, Int32 height) in C:\projects\track-studio\MapStudio.UI\src\Icons\IconManager.cs:line 313 at MapStudio.UI.IconManager.DrawTexture(String key, STGenericTexture texture) in C:\projects\track-studio\MapStudio.UI\src\Icons\IconManager.cs:line 257 at MapStudio.UI.Outliner.LoadTextureIcon(NodeBase node) in C:\projects\track-studio\MapStudio.UI\src\DockedWindows\Outliner\Outliner.cs:line 841 at MapStudio.UI.Outliner.DrawNode(NodeBase node, Single itemHeight, Int32 level) in C:\projects\track-studio\MapStudio.UI\src\DockedWindows\Outliner\Outliner.cs:line 528 at MapStudio.UI.Outliner.DrawNode(NodeBase node, Single itemHeight, Int32 level) in C:\projects\track-studio\MapStudio.UI\src\DockedWindows\Outliner\Outliner.cs:line 770 at MapStudio.UI.Outliner.DrawNode(NodeBase node, Single itemHeight, Int32 level) in C:\projects\track-studio\MapStudio.UI\src\DockedWindows\Outliner\Outliner.cs:line 770 at MapStudio.UI.Outliner.Render() in C:\projects\track-studio\MapStudio.UI\src\DockedWindows\Outliner\Outliner.cs:line 271 at UIFramework.Window.Show() in C:\projects\track-studio\MapStudio.UI\src\UIFramework\Window\Window.cs:line 97 at UIFramework.DockSpaceWindow.Render() in C:\projects\track-studio\MapStudio.UI\src\UIFramework\Window\DockSpaceWindow.cs:line 36 at MapStudio.UI.Workspace.Render() in C:\projects\track-studio\MapStudio.UI\src\Workspace\Workspace.cs:line 235 at UIFramework.Window.Show() in C:\projects\track-studio\MapStudio.UI\src\UIFramework\Window\Window.cs:line 97 at TrackStudio.MainWindow.Render() in C:\projects\track-studio\Track Studio\src\MainWindow.cs:line 138 at UIFramework.Framework.OnRenderFrame(FrameEventArgs e) in C:\projects\track-studio\MapStudio.UI\src\UIFramework\Framework.cs:line 122 at OpenTK.GameWindow.Run(Double updates_per_second, Double frames_per_second) at OpenTK.GameWindow.Run() at TrackStudio.Program.Main(String[] args) in C:\projects\track-studio\Track Studio\src\Program.cs:line 55 Aborted (core dumped)

When trying to enable game shaders I also get the same error relating to DirectXTexNetImpl.dll. I now can't open anything at all, presumably because it remembers I had game shaders selected and it immediately crashes after trying to load them.

After downloading every Track Studio version from around 3 weeks ago (the time I downloaded the one I'm currently using), it seems like these issues only started occuring after 1.0.761 (with 1.0.759 being able to do these things completely fine).

InfinaMii commented 4 days ago

EDIT: I originally thought this was only an issue on release builds, however that happened to be up to chance. Updated comment below:

Upon further testing it seems to be completely random whether this issue occurs or not for a given build. I initially tried debugging it in Rider to get a closer look, but this time it didn't crash or throw any errors. It would then continue to work until I deleted the Debug folder and created a completely clean build, where some of the builds would work correctly but the majority would have the same DirectXTexNetImpl.dll issues.

The "working" builds did still have issues though - even though I could now see the textures folder and game shaders, trying to export any textures gives me completely transparent images (still the correct resolution, but every pixel is #00000000). There also aren't any objects in the Assets window, which I didn't realise was already an issue on 1.0.759 and prior releases due to the fact I hadn't been using map objects until now.