Commit 22abfd6e authored by Rico Schüller's avatar Rico Schüller Committed by Alexandre Julliard

d3dx9: Use init function for ID3DXBuffer.

parent 87f6f86c
...@@ -116,27 +116,45 @@ static const struct ID3DXBufferVtbl ID3DXBufferImpl_Vtbl = ...@@ -116,27 +116,45 @@ static const struct ID3DXBufferVtbl ID3DXBufferImpl_Vtbl =
ID3DXBufferImpl_GetBufferSize ID3DXBufferImpl_GetBufferSize
}; };
static HRESULT d3dx9_buffer_init(struct ID3DXBufferImpl *buffer, DWORD size)
{
buffer->ID3DXBuffer_iface.lpVtbl = &ID3DXBufferImpl_Vtbl;
buffer->ref = 1;
buffer->size = size;
buffer->buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
if (!buffer->buffer)
{
ERR("Failed to allocate buffer memory\n");
return E_OUTOFMEMORY;
}
return D3D_OK;
}
HRESULT WINAPI D3DXCreateBuffer(DWORD size, LPD3DXBUFFER *buffer) HRESULT WINAPI D3DXCreateBuffer(DWORD size, LPD3DXBUFFER *buffer)
{ {
struct ID3DXBufferImpl *object; struct ID3DXBufferImpl *object;
HRESULT hr;
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
if (object == NULL) if (!object)
{ {
*buffer = NULL; ERR("Failed to allocate buffer memory\n");
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
object->ID3DXBuffer_iface.lpVtbl = &ID3DXBufferImpl_Vtbl;
object->ref = 1; hr = d3dx9_buffer_init(object, size);
object->size = size; if (FAILED(hr))
object->buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
if (object->buffer == NULL)
{ {
WARN("Failed to initialize buffer, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object); HeapFree(GetProcessHeap(), 0, object);
*buffer = NULL; return hr;
return E_OUTOFMEMORY;
} }
*buffer = &object->ID3DXBuffer_iface; *buffer = &object->ID3DXBuffer_iface;
TRACE("Created ID3DBuffer %p\n", *buffer);
return D3D_OK; return D3D_OK;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment