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;
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
}
@@ -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;
}
@@ -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,
@@ -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;
}
+2 -2
View File
@@ -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());
}
}