Stop two of same game loading at once on Mac
BlitzMax Forums/BlitzMax Programming/Stop two of same game loading at once on Mac
| ||
Hiya, on the PC I am able to create a Mutex in memory once my game has loaded and thus if someone tries to load another copy, the second copy can auto-shut down. Is there a way to do this on the Mac please? Thanks! |
| ||
I can't find a way to launch two copies of my game on the Mac without copying the executable. If I double-click the icon in Finder, it just brings me to the existing running copy of the game. So, if you're trying to protect against people accidentally launching two copies, I'm not sure it's an actual problem on this platform. If you're trying to protect against them doing something intentional, that's a different story. |
| ||
Ah Cool, so it's a non-issue Thanks! |
| ||
Create a lock file. Works on all platforms. Except maybe Windows. |
| ||
I forgot to test it on my Mac. But yeah it fails I can do that nice and simple. |
| ||
I agree with Flameduck I'd go with writing a temporary file then if that file exists already you shut down the app. |
| ||
Except one big problem with lock files is that they can be problematic if the first instance of the game crashes or quits without removing the lock file (power interruption, Os crash, etc.) then trying to re-launch the game will fail until you manually remove the lock file, or do some other magic first to make sure there isn't already another copy running... And if you can do that, there's no need for the lock file in the first place. :-? |
| ||
And when your application crashes unexpectedly without deleting the temp file first, your application will never start again... Actually, for GUI apps on the Mac the entire thing is a non-issue since the OS won't let you start the same app twice. Only command line tools can be launched more than once. In any case, checking the process list for multiple appearances of the same app would be the safe way to do it. Alternatively, you can "play" with sockets, too. Let your app first try to connect to a port on localhost; if a server responds, you know that your app has already been launched and the new instance ends. If there is no response, your app actually becomes the server and proceeds running. In theory that should work. |
| ||
another alternative would be shared memory |
| ||
I knew there was a reason I used a Mutex on the PC. |
| ||
Grey, I'm not getting it - this really is non-issue on the Mac. You just cannot start the same .app twice on OS X, so it's already been taken care of for you. |
| ||
Yep thanks I realise hense my Ah Cool, so it's a non-issue Thanks! post :-) |
| ||
And when your application crashes unexpectedly without deleting the temp file first, your application will never start again... Yes, well that's the downside of using a poor OS/filesystem that doesn't allow you to create "O_EXCL" type atomic files. From what I understand though MacOS does. I knew there was a reason I used a Mutex on the PC. Well yes. See above. |
| ||
confirmed that this is a non-issue by testing myself. |