Now, audio-related failures in SDL_Init are caught too.
| ... | ... |
@@ -168,10 +168,24 @@ static int |
| 168 | 168 |
init(void) |
| 169 | 169 |
{
|
| 170 | 170 |
SDL_AudioSpec as; |
| 171 |
+ SDL_zero(as); |
|
| 172 |
+ as.freq = SAMPLE_FREQUENCY; |
|
| 173 |
+ as.format = AUDIO_S16; |
|
| 174 |
+ as.channels = 2; |
|
| 175 |
+ as.callback = audio_callback; |
|
| 176 |
+ as.samples = 512; |
|
| 177 |
+ as.userdata = NULL; |
|
| 171 | 178 |
if(!ppu_init(&ppu, 64, 40)) |
| 172 | 179 |
return error("ppu", "Init failure");
|
| 173 |
- if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) |
|
| 174 |
- return error("sdl", SDL_GetError());
|
|
| 180 |
+ if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
|
|
| 181 |
+ error("sdl", SDL_GetError());
|
|
| 182 |
+ if(SDL_Init(SDL_INIT_VIDEO) < 0) |
|
| 183 |
+ return error("sdl", SDL_GetError());
|
|
| 184 |
+ } else {
|
|
| 185 |
+ audio_id = SDL_OpenAudioDevice(NULL, 0, &as, NULL, 0); |
|
| 186 |
+ if(!audio_id) |
|
| 187 |
+ error("sdl_audio", SDL_GetError());
|
|
| 188 |
+ } |
|
| 175 | 189 |
gWindow = SDL_CreateWindow("Uxn", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, (ppu.width + PAD * 2) * zoom, (ppu.height + PAD * 2) * zoom, SDL_WINDOW_SHOWN);
|
| 176 | 190 |
if(gWindow == NULL) |
| 177 | 191 |
return error("sdl_window", SDL_GetError());
|
| ... | ... |
@@ -196,16 +210,6 @@ init(void) |
| 196 | 210 |
ppu.pixels = idxSurface->pixels; |
| 197 | 211 |
SDL_StartTextInput(); |
| 198 | 212 |
SDL_ShowCursor(SDL_DISABLE); |
| 199 |
- SDL_zero(as); |
|
| 200 |
- as.freq = SAMPLE_FREQUENCY; |
|
| 201 |
- as.format = AUDIO_S16; |
|
| 202 |
- as.channels = 2; |
|
| 203 |
- as.callback = audio_callback; |
|
| 204 |
- as.samples = 512; |
|
| 205 |
- as.userdata = NULL; |
|
| 206 |
- audio_id = SDL_OpenAudioDevice(NULL, 0, &as, NULL, 0); |
|
| 207 |
- if(!audio_id) |
|
| 208 |
- error("sdl_audio", SDL_GetError());
|
|
| 209 | 213 |
return 1; |
| 210 | 214 |
} |
| 211 | 215 |
|