@@ -222,7 +222,9 @@ public async Task StartMpf(MachineState initialState, CancellationToken ct)
222
222
}
223
223
catch ( Exception ex )
224
224
{
225
- _mpfProcess ? . Kill ( ) ;
225
+ if ( _mpfProcess != null && ! _mpfProcess . HasExited )
226
+ _mpfProcess . Kill ( ) ;
227
+
226
228
_mpfProcess ? . Dispose ( ) ;
227
229
_mpfProcess = null ;
228
230
MpfState = MpfState . NotConnected ;
@@ -306,7 +308,7 @@ await Task.WhenAny(
306
308
) != processExited . Task
307
309
&& ! _mpfProcess . HasExited
308
310
)
309
- _mpfProcess ? . Kill ( ) ;
311
+ _mpfProcess . Kill ( ) ;
310
312
}
311
313
312
314
_receiveMpfCommandsTask = null ;
@@ -344,7 +346,8 @@ private Process StartMpfProcess()
344
346
{
345
347
// On Linux and macOS, start the process through the terminal so it has a window.
346
348
#if UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
347
- process . StartInfo . Arguments = $ "-e { process . StartInfo . FileName } { process . StartInfo . Arguments } ";
349
+ process . StartInfo . Arguments =
350
+ $ "-e { process . StartInfo . FileName } { process . StartInfo . Arguments } ";
348
351
process . StartInfo . FileName = "x-terminal-emulator" ;
349
352
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
350
353
// There is no way to pass arguments trough the macOS terminal,
@@ -353,7 +356,10 @@ private Process StartMpfProcess()
353
356
// Very convoluted but there is no better way as far as Stackoverflow knows:
354
357
// https://stackoverflow.com/questions/29510815/how-to-pass-command-line-arguments-to-a-program-run-with-the-open-command
355
358
string tmpScriptPath = Path . Combine ( Application . temporaryCachePath , "mpf.sh" ) ;
356
- File . WriteAllText ( tmpScriptPath , $ "#!/bin/bash\n { process . StartInfo . FileName } { process . StartInfo . Arguments } ") ;
359
+ File . WriteAllText (
360
+ tmpScriptPath ,
361
+ $ "#!/bin/bash\n { process . StartInfo . FileName } { process . StartInfo . Arguments } "
362
+ ) ;
357
363
Process . Start ( "chmod" , $ "u+x { tmpScriptPath } ") ;
358
364
process . StartInfo . Arguments = $ "-a Terminal { tmpScriptPath } ";
359
365
process . StartInfo . FileName = "open" ;
0 commit comments