From e022faf54527900e3da19a9ab94f4e03e8d431f7 Mon Sep 17 00:00:00 2001 From: Caleb Cornett Date: Tue, 6 Feb 2024 21:48:16 -0600 Subject: [PATCH] Fix degenerate InputLayout creation when creating graphics pipeline with no vertex attributes --- src/Refresh_Driver_D3D11.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Refresh_Driver_D3D11.c b/src/Refresh_Driver_D3D11.c index 113e650..7af1aa8 100644 --- a/src/Refresh_Driver_D3D11.c +++ b/src/Refresh_Driver_D3D11.c @@ -927,6 +927,12 @@ static ID3D11InputLayout* D3D11_INTERNAL_FetchInputLayout( uint32_t i, bindingIndex; HRESULT res; + /* Don't bother creating/fetching an input layout if there are no attributes. */ + if (inputState.vertexAttributeCount == 0) + { + return NULL; + } + /* Allocate an array of vertex elements */ elementDescs = SDL_stack_alloc( D3D11_INPUT_ELEMENT_DESC, @@ -1119,7 +1125,6 @@ static Refresh_GraphicsPipeline* D3D11_CreateGraphicsPipeline( } else { - /* Not sure if this is even possible, but juuust in case... */ pipeline->vertexStrides = NULL; } @@ -1888,15 +1893,18 @@ static void D3D11_QueueDestroyGraphicsPipeline( ID3D11BlendState_Release(d3dGraphicsPipeline->colorAttachmentBlendState); ID3D11DepthStencilState_Release(d3dGraphicsPipeline->depthStencilState); ID3D11RasterizerState_Release(d3dGraphicsPipeline->rasterizerState); - ID3D11InputLayout_Release(d3dGraphicsPipeline->inputLayout); - - /* FIXME: Release uniform buffers, once that's written in */ + if (d3dGraphicsPipeline->inputLayout) + { + ID3D11InputLayout_Release(d3dGraphicsPipeline->inputLayout); + } if (d3dGraphicsPipeline->vertexStrides) { SDL_free(d3dGraphicsPipeline->vertexStrides); } + /* FIXME: Release uniform buffers, once that's written in */ + SDL_free(d3dGraphicsPipeline); }