dsound: Simplify error handling when creating a sound buffer.
Signed-off-by: Michael Stefaniuc <mstefani@redhat.de> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
7eec8cb4a6
commit
d51d55bab8
|
@ -992,29 +992,28 @@ HRESULT IDirectSoundBufferImpl_Create(
|
||||||
LPWAVEFORMATEX wfex = dsbd->lpwfxFormat;
|
LPWAVEFORMATEX wfex = dsbd->lpwfxFormat;
|
||||||
HRESULT err = DS_OK;
|
HRESULT err = DS_OK;
|
||||||
DWORD capf = 0;
|
DWORD capf = 0;
|
||||||
|
|
||||||
TRACE("(%p,%p,%p)\n",device,pdsb,dsbd);
|
TRACE("(%p,%p,%p)\n",device,pdsb,dsbd);
|
||||||
|
|
||||||
|
*pdsb = NULL;
|
||||||
|
|
||||||
if (dsbd->dwBufferBytes < DSBSIZE_MIN || dsbd->dwBufferBytes > DSBSIZE_MAX) {
|
if (dsbd->dwBufferBytes < DSBSIZE_MIN || dsbd->dwBufferBytes > DSBSIZE_MAX) {
|
||||||
WARN("invalid parameter: dsbd->dwBufferBytes = %d\n", dsbd->dwBufferBytes);
|
WARN("invalid parameter: dsbd->dwBufferBytes = %d\n", dsbd->dwBufferBytes);
|
||||||
*pdsb = NULL;
|
|
||||||
return DSERR_INVALIDPARAM; /* FIXME: which error? */
|
return DSERR_INVALIDPARAM; /* FIXME: which error? */
|
||||||
}
|
}
|
||||||
|
|
||||||
dsb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
|
dsb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
|
||||||
|
|
||||||
if (dsb == 0) {
|
if (!dsb)
|
||||||
WARN("out of memory\n");
|
|
||||||
*pdsb = NULL;
|
|
||||||
return DSERR_OUTOFMEMORY;
|
return DSERR_OUTOFMEMORY;
|
||||||
}
|
|
||||||
|
|
||||||
TRACE("Created buffer at %p\n", dsb);
|
TRACE("Created buffer at %p\n", dsb);
|
||||||
|
|
||||||
dsb->ref = 0;
|
dsb->ref = 1;
|
||||||
dsb->refn = 0;
|
dsb->refn = 0;
|
||||||
dsb->ref3D = 0;
|
dsb->ref3D = 0;
|
||||||
dsb->refiks = 0;
|
dsb->refiks = 0;
|
||||||
dsb->numIfaces = 0;
|
dsb->numIfaces = 1;
|
||||||
dsb->device = device;
|
dsb->device = device;
|
||||||
dsb->IDirectSoundBuffer8_iface.lpVtbl = &dsbvt;
|
dsb->IDirectSoundBuffer8_iface.lpVtbl = &dsbvt;
|
||||||
dsb->IDirectSoundNotify_iface.lpVtbl = &dsnvt;
|
dsb->IDirectSoundNotify_iface.lpVtbl = &dsnvt;
|
||||||
|
@ -1025,9 +1024,8 @@ HRESULT IDirectSoundBufferImpl_Create(
|
||||||
CopyMemory(&dsb->dsbd, dsbd, dsbd->dwSize);
|
CopyMemory(&dsb->dsbd, dsbd, dsbd->dwSize);
|
||||||
|
|
||||||
dsb->pwfx = DSOUND_CopyFormat(wfex);
|
dsb->pwfx = DSOUND_CopyFormat(wfex);
|
||||||
if (dsb->pwfx == NULL) {
|
if (!dsb->pwfx) {
|
||||||
HeapFree(GetProcessHeap(),0,dsb);
|
IDirectSoundBuffer8_Release(&dsb->IDirectSoundBuffer8_iface);
|
||||||
*pdsb = NULL;
|
|
||||||
return DSERR_OUTOFMEMORY;
|
return DSERR_OUTOFMEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1052,22 +1050,16 @@ HRESULT IDirectSoundBufferImpl_Create(
|
||||||
|
|
||||||
/* Allocate an empty buffer */
|
/* Allocate an empty buffer */
|
||||||
dsb->buffer = HeapAlloc(GetProcessHeap(),0,sizeof(*(dsb->buffer)));
|
dsb->buffer = HeapAlloc(GetProcessHeap(),0,sizeof(*(dsb->buffer)));
|
||||||
if (dsb->buffer == NULL) {
|
if (!dsb->buffer) {
|
||||||
WARN("out of memory\n");
|
IDirectSoundBuffer8_Release(&dsb->IDirectSoundBuffer8_iface);
|
||||||
HeapFree(GetProcessHeap(),0,dsb->pwfx);
|
|
||||||
HeapFree(GetProcessHeap(),0,dsb);
|
|
||||||
*pdsb = NULL;
|
|
||||||
return DSERR_OUTOFMEMORY;
|
return DSERR_OUTOFMEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate system memory for buffer */
|
/* Allocate system memory for buffer */
|
||||||
dsb->buffer->memory = HeapAlloc(GetProcessHeap(),0,dsb->buflen);
|
dsb->buffer->memory = HeapAlloc(GetProcessHeap(),0,dsb->buflen);
|
||||||
if (dsb->buffer->memory == NULL) {
|
if (!dsb->buffer->memory) {
|
||||||
WARN("out of memory\n");
|
WARN("out of memory\n");
|
||||||
HeapFree(GetProcessHeap(),0,dsb->pwfx);
|
IDirectSoundBuffer8_Release(&dsb->IDirectSoundBuffer8_iface);
|
||||||
HeapFree(GetProcessHeap(),0,dsb->buffer);
|
|
||||||
HeapFree(GetProcessHeap(),0,dsb);
|
|
||||||
*pdsb = NULL;
|
|
||||||
return DSERR_OUTOFMEMORY;
|
return DSERR_OUTOFMEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1118,18 +1110,12 @@ HRESULT IDirectSoundBufferImpl_Create(
|
||||||
/* register buffer if not primary */
|
/* register buffer if not primary */
|
||||||
if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER)) {
|
if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER)) {
|
||||||
err = DirectSoundDevice_AddBuffer(device, dsb);
|
err = DirectSoundDevice_AddBuffer(device, dsb);
|
||||||
if (err != DS_OK) {
|
if (err == DS_OK)
|
||||||
HeapFree(GetProcessHeap(),0,dsb->buffer->memory);
|
*pdsb = dsb;
|
||||||
HeapFree(GetProcessHeap(),0,dsb->buffer);
|
else
|
||||||
RtlDeleteResource(&dsb->lock);
|
IDirectSoundBuffer8_Release(&dsb->IDirectSoundBuffer8_iface);
|
||||||
HeapFree(GetProcessHeap(),0,dsb->pwfx);
|
|
||||||
HeapFree(GetProcessHeap(),0,dsb);
|
|
||||||
dsb = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IDirectSoundBuffer8_AddRef(&dsb->IDirectSoundBuffer8_iface);
|
|
||||||
*pdsb = dsb;
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue