From: Matteo Bruni Subject: [PATCH v2 4/6] ddraw: Keep a ddraw object reference in d3d7 vertex buffers. Message-Id: <20170224183729.6736-4-mbruni@codeweavers.com> Date: Fri, 24 Feb 2017 19:37:27 +0100 In-Reply-To: <20170224183729.6736-1-mbruni@codeweavers.com> References: <20170224183729.6736-1-mbruni@codeweavers.com> Signed-off-by: Matteo Bruni --- For bug 38307. With this it doesn't crash anymore for me but it still fails with a "Runtime Error : ERROR 10. " messagebox a bit later. v2: Modified for the changes in the previous patch. Split tests out. dlls/ddraw/ddraw.c | 1 + dlls/ddraw/vertexbuffer.c | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c index c5fc266..696f556 100644 --- a/dlls/ddraw/ddraw.c +++ b/dlls/ddraw/ddraw.c @@ -4257,6 +4257,7 @@ static HRESULT WINAPI d3d7_CreateVertexBuffer(IDirect3D7 *iface, D3DVERTEXBUFFER { TRACE("Created vertex buffer %p.\n", object); *vertex_buffer = &object->IDirect3DVertexBuffer7_iface; + IDirectDraw7_AddRef(&ddraw->IDirectDraw7_iface); } else WARN("Failed to create vertex buffer, hr %#x.\n", hr); diff --git a/dlls/ddraw/vertexbuffer.c b/dlls/ddraw/vertexbuffer.c index 515c86e..43abeb7 100644 --- a/dlls/ddraw/vertexbuffer.c +++ b/dlls/ddraw/vertexbuffer.c @@ -81,25 +81,27 @@ static ULONG WINAPI d3d_vertex_buffer7_Release(IDirect3DVertexBuffer7 *iface) TRACE("%p decreasing refcount to %u.\n", buffer, ref); - if (ref == 0) + if (!ref) { - struct wined3d_buffer *curVB = NULL; + struct wined3d_buffer *vb = NULL; UINT offset, stride; - /* D3D7 Vertex buffers don't stay bound in the device, they are passed - * as a parameter to drawPrimitiveVB. DrawPrimitiveVB sets them as the - * stream source in wined3d, and they should get unset there before + /* D3D7 vertex buffers don't stay bound in the device, they are passed + * as a parameter to DrawPrimitiveVB. DrawPrimitiveVB sets them as the + * stream source in wined3d and they should get unset there before * they are destroyed. */ wined3d_mutex_lock(); - wined3d_device_get_stream_source(buffer->ddraw->wined3d_device, - 0, &curVB, &offset, &stride); - if (curVB == buffer->wined3d_buffer) + wined3d_device_get_stream_source(buffer->ddraw->wined3d_device, 0, &vb, &offset, &stride); + if (vb == buffer->wined3d_buffer) wined3d_device_set_stream_source(buffer->ddraw->wined3d_device, 0, NULL, 0, 0); wined3d_vertex_declaration_decref(buffer->wined3d_declaration); wined3d_buffer_decref(buffer->wined3d_buffer); wined3d_mutex_unlock(); + if (buffer->version == 7) + IDirectDraw7_Release(&buffer->ddraw->IDirectDraw7_iface); + HeapFree(GetProcessHeap(), 0, buffer); } -- 2.10.2