Mercurial > touhou
diff pytouhou/lib/sdl.pyx @ 501:4778c482f24a
Make SDL(sound=False) work again, and disable sound if an exception occurs while setting it up.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 23 Oct 2013 18:24:07 +0200 |
parents | 2276229282fd |
children | b39ad30c6620 |
line wrap: on
line diff
--- a/pytouhou/lib/sdl.pyx +++ b/pytouhou/lib/sdl.pyx @@ -12,6 +12,11 @@ ## GNU General Public License for more details. ## +from pytouhou.utils.helpers import get_logger + +logger = get_logger(__name__) + + GL_CONTEXT_MAJOR_VERSION = SDL_GL_CONTEXT_MAJOR_VERSION GL_CONTEXT_MINOR_VERSION = SDL_GL_CONTEXT_MINOR_VERSION GL_DOUBLEBUFFER = SDL_GL_DOUBLEBUFFER @@ -56,8 +61,13 @@ class SDL(object): if self.sound: mix_init(0) - mix_open_audio(44100, MIX_DEFAULT_FORMAT, 2, 4096) - mix_allocate_channels(MAX_CHANNELS) #TODO: make it dependent on the SFX number. + try: + mix_open_audio(44100, MIX_DEFAULT_FORMAT, 2, 4096) + except SDLError as error: + logger.error(u'Impossible to set up audio subsystem: %s', error) + self.sound = False + else: + mix_allocate_channels(MAX_CHANNELS) #TODO: make it dependent on the SFX number. def __exit__(self, *args): if self.sound: