[PATCH vkd3d 3/5] vkd3d: Check for command allocators having a different vtable.

Conor McCarthy cmccarthy at codeweavers.com
Fri Sep 3 09:58:57 CDT 2021


Signed-off-by: Conor McCarthy <cmccarthy at codeweavers.com>
---
 libs/vkd3d/command.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c
index 9f4a4149..253b9128 100644
--- a/libs/vkd3d/command.c
+++ b/libs/vkd3d/command.c
@@ -1675,11 +1675,10 @@ static const struct ID3D12CommandAllocatorVtbl d3d12_command_allocator_vtbl =
     d3d12_command_allocator_Reset,
 };
 
-static struct d3d12_command_allocator *unsafe_impl_from_ID3D12CommandAllocator(ID3D12CommandAllocator *iface)
+static struct d3d12_command_allocator *checked_impl_from_ID3D12CommandAllocator(ID3D12CommandAllocator *iface)
 {
-    if (!iface)
+    if (iface->lpVtbl != &d3d12_command_allocator_vtbl)
         return NULL;
-    assert(iface->lpVtbl == &d3d12_command_allocator_vtbl);
     return impl_from_ID3D12CommandAllocator(iface);
 }
 
@@ -2370,19 +2369,26 @@ static void d3d12_command_list_reset_state(struct d3d12_command_list *list,
 static HRESULT STDMETHODCALLTYPE d3d12_command_list_Reset(ID3D12GraphicsCommandList2 *iface,
         ID3D12CommandAllocator *allocator, ID3D12PipelineState *initial_pipeline_state)
 {
-    struct d3d12_command_allocator *allocator_impl = unsafe_impl_from_ID3D12CommandAllocator(allocator);
     struct d3d12_command_list *list = impl_from_ID3D12GraphicsCommandList2(iface);
+    struct d3d12_command_allocator *allocator_impl;
     HRESULT hr;
 
     TRACE("iface %p, allocator %p, initial_pipeline_state %p.\n",
             iface, allocator, initial_pipeline_state);
 
-    if (!allocator_impl)
+    if (!allocator)
     {
         WARN("Command allocator is NULL.\n");
         return E_INVALIDARG;
     }
 
+    if (!(allocator_impl = checked_impl_from_ID3D12CommandAllocator(allocator)) || allocator_impl->type != list->type)
+    {
+        WARN("Command list types do not match (allocator %#x, list %#x).\n",
+                allocator_impl ? allocator_impl->type : D3D12_COMMAND_LIST_TYPE_BUNDLE, list->type);
+        return E_INVALIDARG;
+    }
+
     if (list->is_recording)
     {
         WARN("Command list is in the recording state.\n");
@@ -5649,16 +5655,16 @@ HRESULT d3d12_command_list_create(struct d3d12_device *device,
     struct d3d12_command_list *object;
     HRESULT hr;
 
-    if (!(allocator = unsafe_impl_from_ID3D12CommandAllocator(allocator_iface)))
+    if (!allocator_iface)
     {
         WARN("Command allocator is NULL.\n");
         return E_INVALIDARG;
     }
 
-    if (allocator->type != type)
+    if (!(allocator = checked_impl_from_ID3D12CommandAllocator(allocator_iface)) || allocator->type != type)
     {
         WARN("Command list types do not match (allocator %#x, list %#x).\n",
-                allocator->type, type);
+                allocator ? allocator->type : D3D12_COMMAND_LIST_TYPE_BUNDLE, type);
         return E_INVALIDARG;
     }
 
-- 
2.32.0




More information about the wine-devel mailing list