use nonfatal exceptions in drivers

This commit is contained in:
Glenn Maynard
2002-12-21 08:15:35 +00:00
parent 4d1caeb4ce
commit 678a07e035
5 changed files with 14 additions and 17 deletions
+3 -3
View File
@@ -15,7 +15,7 @@ DSound::DSound()
HRESULT hr; HRESULT hr;
if(FAILED(hr=DirectSoundCreate8(NULL, &ds8, NULL))) 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 */ /* Try to set primary mixing privileges */
hr = ds8->SetCooperativeLevel(GetDesktopWindow(), DSSCL_PRIORITY); hr = ds8->SetCooperativeLevel(GetDesktopWindow(), DSSCL_PRIORITY);
@@ -84,12 +84,12 @@ DSoundBuf::DSoundBuf(DSound &ds, DSoundBuf::hw hardware,
IDirectSoundBuffer *sndbuf_buf; IDirectSoundBuffer *sndbuf_buf;
HRESULT hr = ds.GetDS8()->CreateSoundBuffer(&format, &sndbuf_buf, NULL); HRESULT hr = ds.GetDS8()->CreateSoundBuffer(&format, &sndbuf_buf, NULL);
if (FAILED(hr)) if (FAILED(hr))
throw "CreateSoundBuffer failed"; RageException::ThrowNonfatal(hr_ssprintf(hr, "CreateSoundBuffer failed"));
sndbuf_buf->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*) &buf); sndbuf_buf->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*) &buf);
if(buf == NULL) if(buf == NULL)
throw "foo"; // XXX RageException::ThrowNonfatal("foo"); // XXX
} }
@@ -150,7 +150,7 @@ RageSound_DSound::RageSound_DSound()
/* Don't bother wasting time trying to create buffers if we're /* Don't bother wasting time trying to create buffers if we're
* emulated. This also gives us better diagnostic information. */ * emulated. This also gives us better diagnostic information. */
if(ds.IsEmulated()) 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. */ /* Create a bunch of streams and put them into the stream pool. */
for(int i = 0; i < 32; ++i) { for(int i = 0; i < 32; ++i) {
@@ -159,7 +159,7 @@ RageSound_DSound::RageSound_DSound()
newbuf = new DSoundBuf(ds, newbuf = new DSoundBuf(ds,
DSoundBuf::HW_HARDWARE, DSoundBuf::HW_HARDWARE,
channels, samplerate, 16, buffersize); channels, samplerate, 16, buffersize);
} catch(const char *e) { } catch(const RageException &e) {
/* If we didn't get at least 8, fail. */ /* If we didn't get at least 8, fail. */
if(i >= 8) break; /* OK */ if(i >= 8) break; /* OK */
@@ -171,9 +171,9 @@ RageSound_DSound::RageSound_DSound()
{ {
/* We created at least one hardware buffer. */ /* 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); 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; stream *s = new stream;
@@ -207,7 +207,7 @@ void RageSound_DSound::StartMixing(RageSound *snd)
} }
if(i == stream_pool.size()) { 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); SOUNDMAN->AddFakeSound(snd);
return; return;
} }
@@ -163,13 +163,10 @@ RageSound_DSound_Software::RageSound_DSound_Software()
{ {
shutdown = false; 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 /* If we're emulated, we're better off with the WaveOut driver; DS
* emulation tends to be desynced. */ * emulation tends to be desynced. */
if(ds.IsEmulated()) 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. */ /* Create a DirectSound stream, but don't force it into hardware. */
str_ds = new DSoundBuf(ds, str_ds = new DSoundBuf(ds,
@@ -91,7 +91,7 @@ bool RageSound_WaveOut::GetPCM()
MMRESULT ret = waveOutWrite(wo, &buffers[b], sizeof(buffers[b])); MMRESULT ret = waveOutWrite(wo, &buffers[b], sizeof(buffers[b]));
if(ret != MMSYSERR_NOERROR) if(ret != MMSYSERR_NOERROR)
throw "blah"; RageException::ThrowNonfatal("blah"); // XXX
/* Increment last_cursor_pos to point at where the data we're about to /* Increment last_cursor_pos to point at where the data we're about to
* ask for will actually be played. */ * ask for will actually be played. */
@@ -177,7 +177,7 @@ RageSound_WaveOut::RageSound_WaveOut()
(DWORD_PTR) sound_event, NULL, CALLBACK_EVENT); (DWORD_PTR) sound_event, NULL, CALLBACK_EVENT);
if(ret != MMSYSERR_NOERROR) if(ret != MMSYSERR_NOERROR)
throw "blah"; RageException::ThrowNonfatal("blah"); // XXX
for(int b = 0; b < num_chunks; ++b) for(int b = 0; b < num_chunks; ++b)
{ {
@@ -186,7 +186,7 @@ RageSound_WaveOut::RageSound_WaveOut()
buffers[b].lpData = new char[chunksize]; buffers[b].lpData = new char[chunksize];
ret = waveOutPrepareHeader(wo, &buffers[b], sizeof(buffers[b])); ret = waveOutPrepareHeader(wo, &buffers[b], sizeof(buffers[b]));
if(ret != MMSYSERR_NOERROR) if(ret != MMSYSERR_NOERROR)
throw "blah"; RageException::ThrowNonfatal("blah"); // XXX
buffers[b].dwFlags |= WHDR_DONE; buffers[b].dwFlags |= WHDR_DONE;
} }
+2 -2
View File
@@ -39,8 +39,8 @@ RageSoundDriver *MakeRageSoundDriver(CString drivers)
LOG->Warn("Unknown sound driver name: %s", DriversToTry[i].GetString()); LOG->Warn("Unknown sound driver name: %s", DriversToTry[i].GetString());
} }
catch(const char *e) { catch(const RageException &e) {
LOG->Trace("Couldn't load driver %s: %s", DriversToTry[i].GetString(), e); LOG->Trace("Couldn't load driver %s: %s", DriversToTry[i].GetString(), e.what());
} }
} }