]> git.draconx.ca Git - gentoo-draconx.git/blob - app-emulation/wine/files/0001-dsound-Restore-old-format-on-SetFormat-failure.patch
mplus-outline-fonts: Remove ebuild.
[gentoo-draconx.git] / app-emulation / wine / files / 0001-dsound-Restore-old-format-on-SetFormat-failure.patch
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.
5
6 The Typing of the Dead, and apparently some other games, expect this to
7 happen.
8
9 Fixes bug #18823.
10 ---
11  dlls/dsound/primary.c |   20 +++++++++++++++-----
12  1 files changed, 15 insertions(+), 5 deletions(-)
13
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
19         return DS_OK;
20  }
21  
22 +static DWORD DSOUND_GetFormatSize(LPCWAVEFORMATEX wfex)
23 +{
24 +       if (wfex->wFormatTag == WAVE_FORMAT_PCM)
25 +               return sizeof(WAVEFORMATEX);
26 +       else
27 +               return sizeof(WAVEFORMATEX) + wfex->cbSize;
28 +}
29 +
30  LPWAVEFORMATEX DSOUND_CopyFormat(LPCWAVEFORMATEX wfex)
31  {
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);
36         if (pwfx == NULL) {
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;
42 +               oldpwfx = NULL;
43                 err = DSERR_OUTOFMEMORY;
44                 goto done;
45         }
46 -       /* TODO: on failure below (bad format?), reinstall oldpwfx */
47 -       HeapFree(GetProcessHeap(), 0, oldpwfx);
48  
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
52                 }
53  
54                 if (err != DSERR_BUFFERLOST && FAILED(err)) {
55 +                       DWORD size = DSOUND_GetFormatSize(oldpwfx);
56                         WARN("IDsDriverBuffer_SetFormat failed\n");
57 -                       if (!forced)
58 +                       if (!forced) {
59 +                               CopyMemory(device->pwfx, oldpwfx, size);
60                                 err = DS_OK;
61 +                       }
62                         goto done;
63                 }
64  
65 @@ -599,6 +608,7 @@ done:
66         RtlReleaseResource(&(device->buffer_list_lock));
67         /* **** */
68  
69 +       HeapFree(GetProcessHeap(), 0, oldpwfx);
70         return err;
71  }
72  
73 -- 
74 1.7.2.2
75