Operating system or device - Godot version:
macOS Sierra 10.12.6 - Godot 3.0 Alpha 1
Issue description:
Whenever I export a game to macOS and try to run it, it immediately crashes. This happens both with an export made from Windows and one made from macOS. When I use Terminal to execute the binary itself (under Content/MacOS/), I get the following error: "error: Couldn't load game path '.'".
I can however execute the .app file if I do so from within the godot project folder. It's only when I move it somewhere outside of that folder that it no longer works.
I'm using Godot 3.0 Alpha 1 and I'm sure I'm using the right export templates.
Steps to reproduce:
Link to minimal example project:
Godot_empty.zip
Owh weird, I have to give this a try when I'm home.
@BastiaanOlij Did you ever get home?
FWIW, this error means that the data pack is missing.
@reduz lol, yeah I did but completely forgot about this.. Just tried it and something has indeed changed.
As far as I can see, it does create the package properly, puts the data pack in resources but when started it doesn't load it. Godot does tend to crash in this scenario, I fixed a bunch of things around this on Iphone, never got around to checking it for OSX.
I don't know what has changed in the loading procedure however. I'll do some more testing.
edit if I read the code in godot_main_osx.mm correctly it only changes the working directory to resources if the application bundle it started from Finder as only then the full path is given, when the app is started directly from terminal the first parameter is usually something like ./myexecutable
You can trick it by specifying the full path in terminal. So far I've not been able to get useful output in console when starting through finder ever since going up to 10.12, very annoying.
Anyway, it is indeed not loading the data pack. Its getting late right now but I'll find some time to add some output to strategic places and see whether its not looking for the correct file, or whether its not able to open it.
Ok, finally had a bit of time to investigate this further.
I don't know if these also apply to 2.1.4, I've only tested this in 3.0.
On OSX you place the data pack in the resources folder of the application bundle. For this there is code in godot_main_osx.mm which will change the current path to the resources folder. Because we now use the executables name for the data pack name it is extracted by calling get_basename which instead of just returning the base name also returns the path. It is thus ignoring the current directory and it can't find the data pack. Also get_basename searches for the last . to strip of the file extension but this is often not used on OSX so its strips off everything until the app bundles .app.
That said, it looks like Android and iOS have similar issues with placing the datapack and someone made a much more elegant solution by adding a get_resource_dir function to the OS.
I'm going to change the code in OSX to have this return the resource folder. That should fix this.
edit that last bit doesn't work because its not designed to open a datapack file so I'm actually going to follow through with my note below
One small foot note on this btw, @akien-mga, @reduz , there is an additional issue with get_basename.
As it searches for the . and therefor strips of the whole pack to get the name of the application bundle, that is a name that someone can easily change breaking the load.
It really should first strip off the path to get the executable name, and then search for the . in the resulting string. That is what I would expect get_basename to do anyway, its usually a function that returns the name of a file excluding path?
Fixed by #11062.
Most helpful comment
@BastiaanOlij Did you ever get home?