[PATCH] wined3d: Check pointer before use
Alistair Leslie-Hughes
leslie_alistair at hotmail.com
Tue Apr 25 01:01:04 CDT 2017
Test was provided by Józef Kucia.
Fixes https://bugs.winehq.org/show_bug.cgi?id=42873
Signed-off-by: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
---
dlls/d3d11/tests/d3d11.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++
dlls/wined3d/context.c | 2 +-
2 files changed, 59 insertions(+), 1 deletion(-)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c
index dfe50c6287..2961cc06cb 100644
--- a/dlls/d3d11/tests/d3d11.c
+++ b/dlls/d3d11/tests/d3d11.c
@@ -17567,6 +17567,63 @@ done:
release_test_context(&test_context);
}
+static void test_destroyed_wined3d_context_query_poll(void)
+{
+ struct d3d11_test_context test_context;
+ ID3D11Asynchronous *timestamp_query;
+ ID3D11DeviceContext *context;
+ D3D11_QUERY_DESC query_desc;
+ ID3D11Device *device;
+ UINT64 timestamp;
+ unsigned int i;
+ HRESULT hr;
+
+ static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
+
+ if (!init_test_context(&test_context, NULL))
+ return;
+
+ device = test_context.device;
+ context = test_context.immediate_context;
+
+ query_desc.Query = D3D11_QUERY_TIMESTAMP;
+ query_desc.MiscFlags = 0;
+ hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)×tamp_query);
+ ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
+
+ ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
+ ID3D11DeviceContext_End(context, timestamp_query);
+
+ ID3D11RenderTargetView_Release(test_context.backbuffer_rtv);
+ test_context.backbuffer_rtv = NULL;
+ ID3D11Texture2D_Release(test_context.backbuffer);
+ test_context.backbuffer = NULL;
+ IDXGISwapChain_Release(test_context.swapchain);
+ test_context.swapchain = NULL;
+ test_context.swapchain = create_swapchain(device, test_context.window, NULL);
+ hr = IDXGISwapChain_GetBuffer(test_context.swapchain, 0, &IID_ID3D11Texture2D,
+ (void **)&test_context.backbuffer);
+ ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
+ hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer,
+ NULL, &test_context.backbuffer_rtv);
+ ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
+ ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
+ ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
+
+ for (i = 0; i < 500; ++i)
+ {
+ if ((hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0)) != S_FALSE)
+ break;
+ Sleep(10);
+ }
+ ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
+ hr = ID3D11DeviceContext_GetData(context, timestamp_query, ×tamp, sizeof(timestamp), 0);
+ ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
+
+ ID3D11Asynchronous_Release(timestamp_query);
+ release_test_context(&test_context);
+}
+
START_TEST(d3d11)
{
test_create_device();
@@ -17654,4 +17711,5 @@ START_TEST(d3d11)
test_fl10_stream_output_desc();
test_stream_output_resume();
test_gather();
+ test_destroyed_wined3d_context_query_poll();
}
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 5a899e56d1..76f0fdcc2b 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -3968,7 +3968,7 @@ struct wined3d_context *context_reacquire(const struct wined3d_device *device,
{
struct wined3d_context *current_context;
- if (context->tid != GetCurrentThreadId())
+ if (!context || context->tid != GetCurrentThreadId())
return NULL;
current_context = context_acquire(device, context->current_rt.texture,
--
2.11.0
More information about the wine-patches
mailing list