changeset 602:c84227022765

Don’t crash when a sound file isn’t present in the resources.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 25 Oct 2014 20:02:56 +0200
parents 016f6b937893
children e9300aae4b24
files pytouhou/ui/music.pyx
diffstat 1 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/ui/music.pyx
+++ b/pytouhou/ui/music.pyx
@@ -85,11 +85,11 @@ cdef class SFXPlayer(MusicPlayer):
     cdef Chunk get_sound(self, name):
         cdef Chunk chunk
         if name not in self.sounds:
-            wave_file = self.loader.get_file(name)
             try:
+                wave_file = self.loader.get_file(name)
                 chunk = load_chunk(wave_file)
-            except sdl.SDLError as error:
-                logger.warn(u'Sound “%s” not found: %s', name, error)
+            except (KeyError, sdl.SDLError) as error:
+                logger.warn('Sound “%s” not found: %s', name, error)
                 chunk = None
             else:
                 chunk.set_volume(self.volume)