Repository: missionpinball/mpf

Issue:
Fix crash in high_score mode
Crash when starting high acores mode after game enderd:

```
Traceback (most recent call last):
  File "c:\users\wilder\appdata\local\programs\python\python36\lib\site-packages\mpf\commands\game.py", line 220, in __init__
    MachineController(mpf_path, machine_path, vars(self.args)).run()
  File "c:\users\wilder\appdata\local\programs\python\python36\lib\site-packages\mpf\core\machine.py", line 709, in run
    self._run_loop()
  File "c:\users\wilder\appdata\local\programs\python\python36\lib\site-packages\mpf\core\machine.py", line 769, in _run_loop
    raise self._exception['exception']
  File "c:\users\wilder\appdata\local\programs\python\python36\lib\asyncio\events.py", line 145, in _run
    self._callback(*self._args)
  File "c:\users\wilder\appdata\local\programs\python\python36\lib\site-packages\mpf\core\async_mode.py", line 39, in _done
    future.result()
  File "c:\users\wilder\appdata\local\programs\python\python36\lib\site-packages\mpf\modes\high_score\code\high_score.py", line 127, in _run
    if not self.machine.game.player_list:
AttributeError: 'NoneType' object has no attribute 'player_list'
```

Discussion:

Patch:
diff --git a/mpf/modes/high_score/code/high_score.py b/mpf/modes/high_score/code/high_score.py
index cbaf6c6a8..088ca061d 100644
--- a/mpf/modes/high_score/code/high_score.py
+++ b/mpf/modes/high_score/code/high_score.py
@@ -124,7 +124,8 @@ class HighScore(AsyncMode):
     @asyncio.coroutine
     def _run(self) -> Generator[int, None, None]:
         """Run high score mode."""
-        if not self.machine.game.player_list:
+        if not self.machine.game or not self.machine.game.player_list:
+            self.log.warning("High Score started but there was no game. Will not start.")
             return
 
         new_high_score_list = {}


Test patch:
diff --git a/mpf/tests/test_HighScoreMode.py b/mpf/tests/test_HighScoreMode.py
index 3549565a0..b30082df8 100644
--- a/mpf/tests/test_HighScoreMode.py
+++ b/mpf/tests/test_HighScoreMode.py
@@ -29,6 +29,15 @@ class TestHighScoreMode(MpfBcpTestCase):
             self.machine.game.request_player_add()
             self.advance_time_and_run()
 
+    def test_high_score_without_game(self):
+        # try to start high score mode without a running game
+        self.assertIn("high_score", self.machine.modes)
+        self.assertModeNotRunning("high_score")
+        self.machine.modes["high_score"].start()
+        self.advance_time_and_run()
+        # mode should not start (neither crash)
+        self.assertModeNotRunning("high_score")
+
     def test_default_high_scores(self):
         new_score_data = OrderedDict()
         new_score_data['score'] = [('BRI', 4242),