changeset 369:f305cdd6f6c5

Fix crash with the demo version of Touhou 6
author Thibaut Girka <thib@sitedethib.com>
date Wed, 11 Jul 2012 15:38:15 +0200
parents 71cd4461bb7f
children 74471afbac37
files pytouhou/ui/music.py
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/ui/music.py
+++ b/pytouhou/ui/music.py
@@ -19,6 +19,11 @@ from pyglet.media import AudioData, Audi
 from pyglet.media.riff import WaveSource
 
 
+from pytouhou.utils.helpers import get_logger
+
+logger = get_logger(__name__)
+
+
 class InfiniteWaveSource(WaveSource):
     def __init__(self, filename, start, end, file=None):
         WaveSource.__init__(self, filename, file)
@@ -89,7 +94,12 @@ class MusicPlayer(object):
                 self.bgms.append(None)
                 continue
             posname = bgm[1].replace('bgm/', '').replace('.mid', '.pos')
-            track = resource_loader.get_track(posname)
+            try:
+                track = resource_loader.get_track(posname)
+            except KeyError:
+                self.bgms.append(None)
+                logger.warn('Music description not found: %s', posname)
+                continue
             wavname = join(resource_loader.game_dir, bgm[1].replace('.mid', '.wav'))
             try:
                 source = InfiniteWaveSource(wavname, track.start, track.end)