Mercurial > touhou
comparison pytouhou/ui/music.pyx @ 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 | e15672733c93 |
children | 4ce3ef053a25 |
comparison
equal
deleted
inserted
replaced
601:016f6b937893 | 602:c84227022765 |
---|---|
83 return self.channels[name] | 83 return self.channels[name] |
84 | 84 |
85 cdef Chunk get_sound(self, name): | 85 cdef Chunk get_sound(self, name): |
86 cdef Chunk chunk | 86 cdef Chunk chunk |
87 if name not in self.sounds: | 87 if name not in self.sounds: |
88 wave_file = self.loader.get_file(name) | |
89 try: | 88 try: |
89 wave_file = self.loader.get_file(name) | |
90 chunk = load_chunk(wave_file) | 90 chunk = load_chunk(wave_file) |
91 except sdl.SDLError as error: | 91 except (KeyError, sdl.SDLError) as error: |
92 logger.warn(u'Sound “%s” not found: %s', name, error) | 92 logger.warn('Sound “%s” not found: %s', name, error) |
93 chunk = None | 93 chunk = None |
94 else: | 94 else: |
95 chunk.set_volume(self.volume) | 95 chunk.set_volume(self.volume) |
96 self.sounds[name] = chunk | 96 self.sounds[name] = chunk |
97 return self.sounds[name] | 97 return self.sounds[name] |