Posted: 13th Jun 2007 21:42
Is there anyway to detect is a DBP exe is already running and stop it being launched a secound time?

It's a strange one, but I'm convinced when a user accidentaly launches the game twice the global variable values jump exes!
Posted: 13th Jun 2007 21:53
You need to use a win32 API, namely FindWindow if I remember correctly. Check the msdn documentation.
Posted: 13th Jun 2007 22:04
Maybe it's not the globals maybe it's the advance terrain height function returning zero, something screwie is happening when run twice, and I been over the code with a fine tooth comb looking for bugs several times
Posted: 13th Jun 2007 22:32
nice idea windows killer I'll give that a try seem simple as im already storing a settings file, so maybe leave a timestamp in it so it wont run annother one for 30 secounds or something
Posted: 13th Jun 2007 22:34
Also, a problem with race conditions. What happens if both applications are launched at the same time, and both see no file, both then make the file, so you still end up with two applications open.
Posted: 13th Jun 2007 22:36
They never start at the same it just when someone double clicks twice so it should be fine as one double click will always be a few mico seconds before the second one.
Posted: 13th Jun 2007 22:38
They never start at the same it just when someone double clicks twice so it should be fine as one double click will always be a few mico seconds before the second one.


There will always be a chance of it happening until you use atomic operations, but I think it should be fine to use this method
Posted: 13th Jun 2007 23:35
Using a file will work most of the time, unless:
1. Your program crashes and doesn't remove the file on exit - your program won't run at all until you remove the file.
2. Both exe's test for the file at the same time - two copies of your program run.

You need to use an atomic operation as John Y said.

Luckily, there's a way to do this using system level mutexes, and I've got those included in my utility plug-ins:
+ Code Snippet
make sysobj mutex 1, "MyGame"
if try lock sysobj(1) = 0 then end

wait key


The first line creates a named mutex. The second line attempts to get a unique lock on the mutex. If the TRY LOCK SYSOBJ function returns a 1 it got the lock and it's the first occurrence of your progra,. If it returns a 0, it didn't and is the second or later occurrence of your program.
When the program ends it will automatically release the lock.

Make sure you use a name that is unique to your program - the best way is to generate a GUID. There's a function GENERATE GUID$ in my string plug-in that will generate a unique string every time you run it - use the following code in a standalone program to generate a GUID and put it into the clipboard for this purpose:
+ Code Snippet
write to clipboard  generate guid$()