diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c index 80eb240766b..020b17a8edb 100644 --- a/dlls/d3d9/tests/device.c +++ b/dlls/d3d9/tests/device.c @@ -1505,7 +1505,7 @@ static void test_draw_indexed(void) hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vertex_declaration); ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (0x%08x)\n", hr); - hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration); + hr = IDirect3DDevice9_SetVertexDeclaration(device, NULL); ok(SUCCEEDED(hr), "SetVertexDeclaration failed (0x%08x)\n", hr); hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad), 0, 0, D3DPOOL_DEFAULT, &vertex_buffer, NULL); @@ -1538,9 +1538,17 @@ static void test_draw_indexed(void) ok(hr == D3DERR_INVALIDCALL, "DrawIndexedPrimitive returned 0x%08x, expected D3DERR_INVALIDCALL (0x%08x)\n", hr, D3DERR_INVALIDCALL); - /* Valid index buffer. Should succeed */ + /* Valid index buffer, NULL vertex declaration. Should fail */ hr = IDirect3DDevice9_SetIndices(device, index_buffer); ok(SUCCEEDED(hr), "SetIndices failed (0x%08x)\n", hr); + hr = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0 /* BaseVertexIndex */, 0 /* MinIndex */, + 4 /* NumVerts */, 0 /* StartIndex */, 2 /*PrimCount */); + ok(hr == D3DERR_INVALIDCALL, "DrawIndexedPrimitive returned 0x%08x, expected D3DERR_INVALIDCALL (0x%08x)\n", + hr, D3DERR_INVALIDCALL); + + /* Valid index buffer and vertex declaration. Should succeed */ + hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration); + ok(SUCCEEDED(hr), "SetVertexDeclaration failed (0x%08x)\n", hr); hr = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0 /* BaseVertexIndex */, 0 /* MinIndex */, 4 /* NumVerts */, 0 /* StartIndex */, 2 /*PrimCount */); ok(SUCCEEDED(hr), "DrawIndexedPrimitive failed (0x%08x)\n", hr); diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 034b04d14ef..53d669efd5f 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -5165,6 +5165,11 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawPrimitive(IWineD3DDevice *iface, WI debug_d3dprimitivetype(PrimitiveType), StartVertex, PrimitiveCount); + if(!This->stateBlock->vertexDecl) { + WARN("(%p) : Called without a valid vertex declaration set\n", This); + return WINED3DERR_INVALIDCALL; + } + /* The index buffer is not needed here, but restore it, otherwise it is hell to keep track of */ if(This->stateBlock->streamIsUP) { IWineD3DDeviceImpl_MarkStateDirty(This, STATE_INDEXBUFFER); @@ -5202,6 +5207,11 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitive(IWineD3DDevice * return WINED3DERR_INVALIDCALL; } + if(!This->stateBlock->vertexDecl) { + WARN("(%p) : Called without a valid vertex declaration set\n", This); + return WINED3DERR_INVALIDCALL; + } + if(This->stateBlock->streamIsUP) { IWineD3DDeviceImpl_MarkStateDirty(This, STATE_INDEXBUFFER); This->stateBlock->streamIsUP = FALSE; @@ -5240,6 +5250,11 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawPrimitiveUP(IWineD3DDevice *iface, debug_d3dprimitivetype(PrimitiveType), PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride); + if(!This->stateBlock->vertexDecl) { + WARN("(%p) : Called without a valid vertex declaration set\n", This); + return WINED3DERR_INVALIDCALL; + } + /* Note in the following, it's not this type, but that's the purpose of streamIsUP */ vb = This->stateBlock->streamSource[0]; This->stateBlock->streamSource[0] = (IWineD3DVertexBuffer *)pVertexStreamZeroData; @@ -5280,6 +5295,11 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitiveUP(IWineD3DDevice * MinVertexIndex, NumVertices, PrimitiveCount, pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride); + if(!This->stateBlock->vertexDecl) { + WARN("(%p) : Called without a valid vertex declaration set\n", This); + return WINED3DERR_INVALIDCALL; + } + if (IndexDataFormat == WINED3DFMT_INDEX16) { idxStride = 2; } else {