1 From 5f3e18eb2771b875388b6748409325cfeb29061d Mon Sep 17 00:00:00 2001
2 From: Nick Bowler <nbowler@draconx.ca>
3 Date: Sat, 2 Oct 2010 12:50:09 -0400
4 Subject: [PATCH] dsound: Restore old format on SetFormat failure.
6 The Typing of the Dead, and apparently some other games, expect this to
11 dlls/dsound/primary.c | 20 +++++++++++++++-----
12 1 files changed, 15 insertions(+), 5 deletions(-)
14 diff --git a/dlls/dsound/primary.c b/dlls/dsound/primary.c
15 index 8a054f8..aa8450f 100644
16 --- a/dlls/dsound/primary.c
17 +++ b/dlls/dsound/primary.c
18 @@ -441,10 +441,17 @@ HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LP
22 +static DWORD DSOUND_GetFormatSize(LPCWAVEFORMATEX wfex)
24 + if (wfex->wFormatTag == WAVE_FORMAT_PCM)
25 + return sizeof(WAVEFORMATEX);
27 + return sizeof(WAVEFORMATEX) + wfex->cbSize;
30 LPWAVEFORMATEX DSOUND_CopyFormat(LPCWAVEFORMATEX wfex)
32 - DWORD size = wfex->wFormatTag == WAVE_FORMAT_PCM ?
33 - sizeof(WAVEFORMATEX) : sizeof(WAVEFORMATEX) + wfex->cbSize;
34 + DWORD size = DSOUND_GetFormatSize(wfex);
35 LPWAVEFORMATEX pwfx = HeapAlloc(GetProcessHeap(),0,size);
37 WARN("out of memory\n");
38 @@ -501,11 +508,10 @@ static HRESULT DSOUND_PrimarySetFormat(DirectSoundDevice *device, LPCWAVEFORMATE
39 device->pwfx = DSOUND_CopyFormat(wfex);
40 if (device->pwfx == NULL) {
41 device->pwfx = oldpwfx;
43 err = DSERR_OUTOFMEMORY;
46 - /* TODO: on failure below (bad format?), reinstall oldpwfx */
47 - HeapFree(GetProcessHeap(), 0, oldpwfx);
49 if (!(device->drvdesc.dwFlags & DSDDESC_DOMMSYSTEMSETFORMAT) && device->hwbuf) {
50 err = IDsDriverBuffer_SetFormat(device->hwbuf, device->pwfx);
51 @@ -520,9 +526,12 @@ static HRESULT DSOUND_PrimarySetFormat(DirectSoundDevice *device, LPCWAVEFORMATE
54 if (err != DSERR_BUFFERLOST && FAILED(err)) {
55 + DWORD size = DSOUND_GetFormatSize(oldpwfx);
56 WARN("IDsDriverBuffer_SetFormat failed\n");
59 + CopyMemory(device->pwfx, oldpwfx, size);
65 @@ -599,6 +608,7 @@ done:
66 RtlReleaseResource(&(device->buffer_list_lock));
69 + HeapFree(GetProcessHeap(), 0, oldpwfx);