From 678a07e0353b19068fccbb4c3e0f6d1d5614a282 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 21 Dec 2002 08:15:35 +0000 Subject: [PATCH] use nonfatal exceptions in drivers --- stepmania/src/arch/Sound/DSoundHelpers.cpp | 6 +++--- stepmania/src/arch/Sound/RageSoundDriver_DSound.cpp | 10 +++++----- .../src/arch/Sound/RageSoundDriver_DSound_Software.cpp | 5 +---- stepmania/src/arch/Sound/RageSoundDriver_WaveOut.cpp | 6 +++--- stepmania/src/arch/arch.cpp | 4 ++-- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/stepmania/src/arch/Sound/DSoundHelpers.cpp b/stepmania/src/arch/Sound/DSoundHelpers.cpp index 4318d5bb71..bf94872989 100644 --- a/stepmania/src/arch/Sound/DSoundHelpers.cpp +++ b/stepmania/src/arch/Sound/DSoundHelpers.cpp @@ -15,7 +15,7 @@ DSound::DSound() HRESULT hr; if(FAILED(hr=DirectSoundCreate8(NULL, &ds8, NULL))) - throw RageException(hr_ssprintf(hr, "DirectSoundCreate8")); + RageException::ThrowNonfatal(hr_ssprintf(hr, "DirectSoundCreate8")); /* Try to set primary mixing privileges */ hr = ds8->SetCooperativeLevel(GetDesktopWindow(), DSSCL_PRIORITY); @@ -84,12 +84,12 @@ DSoundBuf::DSoundBuf(DSound &ds, DSoundBuf::hw hardware, IDirectSoundBuffer *sndbuf_buf; HRESULT hr = ds.GetDS8()->CreateSoundBuffer(&format, &sndbuf_buf, NULL); if (FAILED(hr)) - throw "CreateSoundBuffer failed"; + RageException::ThrowNonfatal(hr_ssprintf(hr, "CreateSoundBuffer failed")); sndbuf_buf->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*) &buf); if(buf == NULL) - throw "foo"; // XXX + RageException::ThrowNonfatal("foo"); // XXX } diff --git a/stepmania/src/arch/Sound/RageSoundDriver_DSound.cpp b/stepmania/src/arch/Sound/RageSoundDriver_DSound.cpp index 8fbc4889db..cac337b523 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_DSound.cpp +++ b/stepmania/src/arch/Sound/RageSoundDriver_DSound.cpp @@ -150,7 +150,7 @@ RageSound_DSound::RageSound_DSound() /* Don't bother wasting time trying to create buffers if we're * emulated. This also gives us better diagnostic information. */ if(ds.IsEmulated()) - throw "Driver unusable (emulated device)"; + RageException::ThrowNonfatal("Driver unusable (emulated device)"); /* Create a bunch of streams and put them into the stream pool. */ for(int i = 0; i < 32; ++i) { @@ -159,7 +159,7 @@ RageSound_DSound::RageSound_DSound() newbuf = new DSoundBuf(ds, DSoundBuf::HW_HARDWARE, channels, samplerate, 16, buffersize); - } catch(const char *e) { + } catch(const RageException &e) { /* If we didn't get at least 8, fail. */ if(i >= 8) break; /* OK */ @@ -171,9 +171,9 @@ RageSound_DSound::RageSound_DSound() { /* We created at least one hardware buffer. */ LOG->Trace("Could only create %i buffers; need at least 8 (failed with %s). DirectSound driver can't be used.", i, e); - throw "Driver unusable (not enough hardware buffers)"; + RageException::ThrowNonfatal("Driver unusable (not enough hardware buffers)"); } - throw "Driver unusable (no hardware buffers)"; + RageException::ThrowNonfatal("Driver unusable (no hardware buffers)"); } stream *s = new stream; @@ -207,7 +207,7 @@ void RageSound_DSound::StartMixing(RageSound *snd) } if(i == stream_pool.size()) { - /* We don't have a free sound buffer. XXX fake it */ + /* We don't have a free sound buffer. Fake it. */ SOUNDMAN->AddFakeSound(snd); return; } diff --git a/stepmania/src/arch/Sound/RageSoundDriver_DSound_Software.cpp b/stepmania/src/arch/Sound/RageSoundDriver_DSound_Software.cpp index 546099eed6..572d1ea6e3 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_DSound_Software.cpp +++ b/stepmania/src/arch/Sound/RageSoundDriver_DSound_Software.cpp @@ -163,13 +163,10 @@ RageSound_DSound_Software::RageSound_DSound_Software() { shutdown = false; - /* XXX make another exception type that doesn't trigger debug stuff - * and use that */ - /* If we're emulated, we're better off with the WaveOut driver; DS * emulation tends to be desynced. */ if(ds.IsEmulated()) - throw "Driver unusable (emulated device)"; + RageException::ThrowNonfatal("Driver unusable (emulated device)"); /* Create a DirectSound stream, but don't force it into hardware. */ str_ds = new DSoundBuf(ds, diff --git a/stepmania/src/arch/Sound/RageSoundDriver_WaveOut.cpp b/stepmania/src/arch/Sound/RageSoundDriver_WaveOut.cpp index 475a386d5c..17313caf52 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_WaveOut.cpp +++ b/stepmania/src/arch/Sound/RageSoundDriver_WaveOut.cpp @@ -91,7 +91,7 @@ bool RageSound_WaveOut::GetPCM() MMRESULT ret = waveOutWrite(wo, &buffers[b], sizeof(buffers[b])); if(ret != MMSYSERR_NOERROR) - throw "blah"; + RageException::ThrowNonfatal("blah"); // XXX /* Increment last_cursor_pos to point at where the data we're about to * ask for will actually be played. */ @@ -177,7 +177,7 @@ RageSound_WaveOut::RageSound_WaveOut() (DWORD_PTR) sound_event, NULL, CALLBACK_EVENT); if(ret != MMSYSERR_NOERROR) - throw "blah"; + RageException::ThrowNonfatal("blah"); // XXX for(int b = 0; b < num_chunks; ++b) { @@ -186,7 +186,7 @@ RageSound_WaveOut::RageSound_WaveOut() buffers[b].lpData = new char[chunksize]; ret = waveOutPrepareHeader(wo, &buffers[b], sizeof(buffers[b])); if(ret != MMSYSERR_NOERROR) - throw "blah"; + RageException::ThrowNonfatal("blah"); // XXX buffers[b].dwFlags |= WHDR_DONE; } diff --git a/stepmania/src/arch/arch.cpp b/stepmania/src/arch/arch.cpp index 5cf6c1d3e1..130fe35e20 100644 --- a/stepmania/src/arch/arch.cpp +++ b/stepmania/src/arch/arch.cpp @@ -39,8 +39,8 @@ RageSoundDriver *MakeRageSoundDriver(CString drivers) LOG->Warn("Unknown sound driver name: %s", DriversToTry[i].GetString()); } - catch(const char *e) { - LOG->Trace("Couldn't load driver %s: %s", DriversToTry[i].GetString(), e); + catch(const RageException &e) { + LOG->Trace("Couldn't load driver %s: %s", DriversToTry[i].GetString(), e.what()); } }