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	Sat Oct 25 18:57:10 2014 +0200
+++ b/pytouhou/ui/music.pyx	Sat Oct 25 20:02:56 2014 +0200
@@ -85,11 +85,11 @@
     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)