Author: Barry deFreese <bdefreese@debian.org>
Description: fix startup when no sound device is available
Bug: http://sf.net/support/tracker.php?aid=3240753
Bug-Debian: http://bugs.debian.org/449328
--- a/src/data.c
+++ b/src/data.c
@@ -51,6 +51,8 @@
 int cursor_w = 0, cursor_x_offset = 0;
 int gun_w = 0, gun_h = 0;
 
+extern int audio_on;
+
 extern SDL_Surface *screen; /* display */
 
 #define SET_ALPHA( surf, alpha ) SDL_SetAlpha( surf, SDL_SRCALPHA | SDL_RLEACCEL, alpha )
@@ -234,6 +236,7 @@
 	ft_menu = ft_chart; ft_menu_highlight = ft_chart_highlight;
 	
 #ifdef AUDIO_ENABLED
+    if ( audio_on ) {
 	wav_expl1 = data_load_sound( "expl1.wav" );
 	wav_expl2 = data_load_sound( "expl2.wav" );
 	wav_expl3 = data_load_sound( "expl3.wav" );
@@ -241,6 +244,7 @@
 	wav_cannon2 = data_load_sound( "gunfire.wav" );
 	wav_click = data_load_sound( "click.wav" );
 	wav_highlight = data_load_sound( "highlight.wav" );
+    }
 #endif
 
 	cr_empty = data_create_cursor( 16, 16, 8, 8,
@@ -288,6 +292,7 @@
 	printf( "%i fonts deleted\n", ft_count );
 	
 #ifdef AUDIO_ENABLED
+    if ( audio_on ) {
 	data_free_sound( &wav_expl1 );
 	data_free_sound( &wav_expl2 );
 	data_free_sound( &wav_expl3 );
@@ -295,6 +300,7 @@
 	data_free_sound( &wav_click );
 	data_free_sound( &wav_highlight );
 	printf( "%i sounds deleted\n", wav_count );
+    }
 #endif
 
 	data_free_cursor( &cr_empty );
--- a/src/main.c
+++ b/src/main.c
@@ -576,10 +576,15 @@
 
   set_player_name_from_env();
 	
-  if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO ) < 0 ) {
+  if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER ) < 0 ) {
     printf( "%s\n", SDL_GetError() );
     exit(1);
   }
+  else if ( SDL_InitSubSystem( SDL_INIT_AUDIO ) < 0 ) {
+    printf( "%s\n", SDL_GetError() );
+    printf( "Disabling sound and continuing...\n" );
+    audio_on = 0;
+  }
   if ( SDL_SetVideoMode( 640, 480, BITDEPTH, 
 			 (fullscreen?SDL_FULLSCREEN:0) | SDL_HWSURFACE | SDL_DOUBLEBUF ) < 0 ) {
     printf( "%s\n", SDL_GetError() );
@@ -592,7 +597,8 @@
 #ifdef AUDIO_ENABLED	
   if ( Mix_OpenAudio( audio_freq, audio_format, audio_channels, 1024 ) < 0 ) {
     printf( "%s\n", SDL_GetError() );
-    exit(1);
+    printf("Disabling sound and continuing\n");
+    audio_on = 0;
   }
   audio_mix_channel_count = Mix_AllocateChannels( 16 );
 #endif
