From 873178c03a56eca4d818369386b0be6ba01b08c4 Mon Sep 17 00:00:00 2001 From: Matteo Bruni Date: Wed, 27 Feb 2019 18:30:09 +0100 Subject: [PATCH] d3d8: Release system memory wined3d buffer only after the draw buffer is destroyed. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=46371 Signed-off-by: Matteo Bruni Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/d3d8/buffer.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/dlls/d3d8/buffer.c b/dlls/d3d8/buffer.c index 8aec654052c..822730ff6dc 100644 --- a/dlls/d3d8/buffer.c +++ b/dlls/d3d8/buffer.c @@ -57,9 +57,10 @@ static ULONG WINAPI d3d8_vertexbuffer_AddRef(IDirect3DVertexBuffer8 *iface) { IDirect3DDevice8_AddRef(buffer->parent_device); wined3d_mutex_lock(); - wined3d_buffer_incref(buffer->wined3d_buffer); if (buffer->draw_buffer) wined3d_buffer_incref(buffer->draw_buffer); + else + wined3d_buffer_incref(buffer->wined3d_buffer); wined3d_mutex_unlock(); } @@ -79,9 +80,10 @@ static ULONG WINAPI d3d8_vertexbuffer_Release(IDirect3DVertexBuffer8 *iface) IDirect3DDevice8 *device = buffer->parent_device; wined3d_mutex_lock(); - wined3d_buffer_decref(buffer->wined3d_buffer); if (draw_buffer) wined3d_buffer_decref(draw_buffer); + else + wined3d_buffer_decref(buffer->wined3d_buffer); wined3d_mutex_unlock(); /* Release the device last, as it may cause the device to be destroyed. */ @@ -269,6 +271,9 @@ static const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl = static void STDMETHODCALLTYPE d3d8_vertexbuffer_wined3d_object_destroyed(void *parent) { struct d3d8_vertexbuffer *buffer = parent; + + if (buffer->draw_buffer) + wined3d_buffer_decref(buffer->wined3d_buffer); d3d8_resource_cleanup(&buffer->resource); heap_free(buffer); } @@ -380,9 +385,10 @@ static ULONG WINAPI d3d8_indexbuffer_AddRef(IDirect3DIndexBuffer8 *iface) { IDirect3DDevice8_AddRef(buffer->parent_device); wined3d_mutex_lock(); - wined3d_buffer_incref(buffer->wined3d_buffer); if (buffer->draw_buffer) wined3d_buffer_incref(buffer->draw_buffer); + else + wined3d_buffer_incref(buffer->wined3d_buffer); wined3d_mutex_unlock(); } @@ -402,9 +408,10 @@ static ULONG WINAPI d3d8_indexbuffer_Release(IDirect3DIndexBuffer8 *iface) IDirect3DDevice8 *device = buffer->parent_device; wined3d_mutex_lock(); - wined3d_buffer_decref(buffer->wined3d_buffer); if (draw_buffer) wined3d_buffer_decref(draw_buffer); + else + wined3d_buffer_decref(buffer->wined3d_buffer); wined3d_mutex_unlock(); /* Release the device last, as it may cause the device to be destroyed. */ @@ -591,6 +598,9 @@ static const IDirect3DIndexBuffer8Vtbl d3d8_indexbuffer_vtbl = static void STDMETHODCALLTYPE d3d8_indexbuffer_wined3d_object_destroyed(void *parent) { struct d3d8_indexbuffer *buffer = parent; + + if (buffer->draw_buffer) + wined3d_buffer_decref(buffer->wined3d_buffer); d3d8_resource_cleanup(&buffer->resource); heap_free(buffer); }