Commit 46572f68 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Refuse to create shaders with a NULL function.

parent 62497e87
...@@ -1599,20 +1599,28 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 ...@@ -1599,20 +1599,28 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8
wined3d_vertex_declaration = ((IDirect3DVertexDeclaration8Impl *)object->vertex_declaration)->wined3d_vertex_declaration; wined3d_vertex_declaration = ((IDirect3DVertexDeclaration8Impl *)object->vertex_declaration)->wined3d_vertex_declaration;
/* Usage is missing ... Use SetRenderState to set the sw vp render state in SetVertexShader */ if (pFunction)
hrc = IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, wined3d_vertex_declaration, pFunction, &object->wineD3DVertexShader, (IUnknown *)object); {
/* Usage is missing ... Use SetRenderState to set the sw vp render state in SetVertexShader */
hrc = IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, wined3d_vertex_declaration,
pFunction, &object->wineD3DVertexShader, (IUnknown *)object);
if (FAILED(hrc)) { if (FAILED(hrc))
/* free up object */ {
FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n"); /* free up object */
free_shader_handle(This, handle); FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
IDirect3DVertexDeclaration8_Release(object->vertex_declaration); free_shader_handle(This, handle);
HeapFree(GetProcessHeap(), 0, object); IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
*ppShader = 0; HeapFree(GetProcessHeap(), 0, object);
} else { *ppShader = 0;
load_local_constants(pDeclaration, object->wineD3DVertexShader); }
TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader); else
{
load_local_constants(pDeclaration, object->wineD3DVertexShader);
TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
}
} }
LeaveCriticalSection(&d3d8_cs); LeaveCriticalSection(&d3d8_cs);
return hrc; return hrc;
...@@ -1706,9 +1714,19 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 ifa ...@@ -1706,9 +1714,19 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 ifa
hrc = D3DERR_INVALIDCALL; hrc = D3DERR_INVALIDCALL;
} else { } else {
IDirect3DVertexShader8Impl *shader = This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)]; IDirect3DVertexShader8Impl *shader = This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
shader ? ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration : NULL); if (shader)
hrc = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, 0 == shader ? NULL : shader->wineD3DVertexShader); {
hrc = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
if (SUCCEEDED(hrc))
hrc = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader->wineD3DVertexShader);
}
else
{
hrc = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice, NULL);
if (SUCCEEDED(hrc)) hrc = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
}
} }
} }
TRACE("(%p) : returning hr(%u)\n", This, hrc); TRACE("(%p) : returning hr(%u)\n", This, hrc);
...@@ -1860,7 +1878,16 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEV ...@@ -1860,7 +1878,16 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEV
} }
shader = This->shader_handles[pVertexShader - (VS_HIGHESTFIXEDFXF + 1)]; shader = This->shader_handles[pVertexShader - (VS_HIGHESTFIXEDFXF + 1)];
hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, pSizeOfData); if (shader->wineD3DVertexShader)
{
hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, pSizeOfData);
}
else
{
*pSizeOfData = 0;
hr = D3D_OK;
}
LeaveCriticalSection(&d3d8_cs); LeaveCriticalSection(&d3d8_cs);
return hr; return hr;
} }
......
...@@ -57,7 +57,7 @@ static ULONG WINAPI IDirect3DVertexShader8Impl_Release(IDirect3DVertexShader8 *i ...@@ -57,7 +57,7 @@ static ULONG WINAPI IDirect3DVertexShader8Impl_Release(IDirect3DVertexShader8 *i
if (ref == 0) { if (ref == 0) {
IDirect3DVertexDeclaration8_Release(This->vertex_declaration); IDirect3DVertexDeclaration8_Release(This->vertex_declaration);
IWineD3DVertexShader_Release(This->wineD3DVertexShader); if (This->wineD3DVertexShader) IWineD3DVertexShader_Release(This->wineD3DVertexShader);
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
} }
return ref; return ref;
......
...@@ -90,7 +90,11 @@ static void test_get_set_vertex_shader(IDirect3DDevice9 *device_ptr) ...@@ -90,7 +90,11 @@ static void test_get_set_vertex_shader(IDirect3DDevice9 *device_ptr)
HRESULT hret = 0; HRESULT hret = 0;
int shader_refcount = 0; int shader_refcount = 0;
int i = 0; int i = 0;
hret = IDirect3DDevice9_CreateVertexShader(device_ptr, NULL, &shader_ptr);
ok(hret == D3DERR_INVALIDCALL, "CreateVertexShader returned %#x, expected D3DERR_INVALIDCALL (%#x).\n",
hret, D3DERR_INVALIDCALL);
hret = IDirect3DDevice9_CreateVertexShader(device_ptr, simple_vs, &shader_ptr); hret = IDirect3DDevice9_CreateVertexShader(device_ptr, simple_vs, &shader_ptr);
ok(hret == D3D_OK && shader_ptr != NULL, "CreateVertexShader returned: hret 0x%x, shader_ptr %p. " ok(hret == D3D_OK && shader_ptr != NULL, "CreateVertexShader returned: hret 0x%x, shader_ptr %p. "
"Expected hret 0x%x, shader_ptr != %p. Aborting.\n", hret, shader_ptr, D3D_OK, NULL); "Expected hret 0x%x, shader_ptr != %p. Aborting.\n", hret, shader_ptr, D3D_OK, NULL);
...@@ -155,6 +159,10 @@ static void test_get_set_pixel_shader(IDirect3DDevice9 *device_ptr) ...@@ -155,6 +159,10 @@ static void test_get_set_pixel_shader(IDirect3DDevice9 *device_ptr)
int shader_refcount = 0; int shader_refcount = 0;
int i = 0; int i = 0;
hret = IDirect3DDevice9_CreatePixelShader(device_ptr, NULL, &shader_ptr);
ok(hret == D3DERR_INVALIDCALL, "CreatePixelShader returned %#x, expected D3DERR_INVALIDCALL (%#x).\n",
hret, D3DERR_INVALIDCALL);
hret = IDirect3DDevice9_CreatePixelShader(device_ptr, simple_ps, &shader_ptr); hret = IDirect3DDevice9_CreatePixelShader(device_ptr, simple_ps, &shader_ptr);
ok(hret == D3D_OK && shader_ptr != NULL, "CreatePixelShader returned: hret 0x%x, shader_ptr %p. " ok(hret == D3D_OK && shader_ptr != NULL, "CreatePixelShader returned: hret 0x%x, shader_ptr %p. "
"Expected hret 0x%x, shader_ptr != %p. Aborting.\n", hret, shader_ptr, D3D_OK, NULL); "Expected hret 0x%x, shader_ptr != %p. Aborting.\n", hret, shader_ptr, D3D_OK, NULL);
......
...@@ -1874,6 +1874,9 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateVertexShader(IWineD3DDevice *ifac ...@@ -1874,6 +1874,9 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateVertexShader(IWineD3DDevice *ifac
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
IWineD3DVertexShaderImpl *object; /* NOTE: impl usage is ok, this is a create */ IWineD3DVertexShaderImpl *object; /* NOTE: impl usage is ok, this is a create */
HRESULT hr = WINED3D_OK; HRESULT hr = WINED3D_OK;
if (!pFunction) return WINED3DERR_INVALIDCALL;
D3DCREATESHADEROBJECTINSTANCE(object, VertexShader) D3DCREATESHADEROBJECTINSTANCE(object, VertexShader)
object->baseShader.shader_ins = IWineD3DVertexShaderImpl_shader_ins; object->baseShader.shader_ins = IWineD3DVertexShaderImpl_shader_ins;
...@@ -1900,6 +1903,8 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreatePixelShader(IWineD3DDevice *iface ...@@ -1900,6 +1903,8 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreatePixelShader(IWineD3DDevice *iface
IWineD3DPixelShaderImpl *object; /* NOTE: impl allowed, this is a create */ IWineD3DPixelShaderImpl *object; /* NOTE: impl allowed, this is a create */
HRESULT hr = WINED3D_OK; HRESULT hr = WINED3D_OK;
if (!pFunction) return WINED3DERR_INVALIDCALL;
D3DCREATESHADEROBJECTINSTANCE(object, PixelShader) D3DCREATESHADEROBJECTINSTANCE(object, PixelShader)
object->baseShader.shader_ins = IWineD3DPixelShaderImpl_shader_ins; object->baseShader.shader_ins = IWineD3DPixelShaderImpl_shader_ins;
hr = IWineD3DPixelShader_SetFunction(*ppPixelShader, pFunction); hr = IWineD3DPixelShader_SetFunction(*ppPixelShader, pFunction);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment