[vlc-commits] direct3d11: fix resource leaks
Steve Lhomme
git at videolan.org
Tue May 26 09:37:27 CEST 2015
vlc | branch: master | Steve Lhomme <robUx4 at videolabs.io> | Mon May 25 13:49:47 2015 +0200| [1f897702d7691ebf7f1d5b46af82be72413d3f15] | committer: Jean-Baptiste Kempf
direct3d11: fix resource leaks
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1f897702d7691ebf7f1d5b46af82be72413d3f15
---
modules/video_output/msw/direct3d11.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/modules/video_output/msw/direct3d11.c b/modules/video_output/msw/direct3d11.c
index 82caf0b..290c636 100644
--- a/modules/video_output/msw/direct3d11.c
+++ b/modules/video_output/msw/direct3d11.c
@@ -598,6 +598,7 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
hr = IDXGIAdapter_EnumOutputs(dxgiadapter, 0, &output);
if (FAILED(hr)) {
msg_Err(vd, "Could not Enumerate DXGI Outputs. (hr=0x%lX)", hr);
+ IDXGIAdapter_Release(dxgiadapter);
return VLC_EGENERIC;
}
@@ -611,6 +612,7 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
hr = IDXGIOutput_FindClosestMatchingMode(output, &md, &scd.BufferDesc, NULL);
if (FAILED(hr)) {
msg_Err(vd, "Failed to find a supported video mode. (hr=0x%lX)", hr);
+ IDXGIAdapter_Release(dxgiadapter);
return VLC_EGENERIC;
}
@@ -623,6 +625,7 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
featureLevels, ARRAYSIZE(featureLevels),
D3D11_SDK_VERSION, &scd, &sys->dxgiswapChain,
&sys->d3ddevice, NULL, &sys->d3dcontext);
+ IDXGIAdapter_Release(dxgiadapter);
if (FAILED(hr)) {
msg_Err(vd, "Could not Create the D3D11 device and SwapChain. (hr=0x%lX)", hr);
return VLC_EGENERIC;
@@ -656,19 +659,21 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
}
hr = IDXGIDevice_GetAdapter(pDXGIDevice, &dxgiadapter);
+ IDXGIAdapter_Release(pDXGIDevice);
if (FAILED(hr)) {
msg_Err(vd, "Could not get the DXGI Adapter. (hr=0x%lX)", hr);
return VLC_EGENERIC;
}
hr = IDXGIAdapter_GetParent(dxgiadapter, &IID_IDXGIFactory, (void **)&sys->dxgifactory);
+ IDXGIAdapter_Release(dxgiadapter);
if (FAILED(hr)) {
msg_Err(vd, "Could not get the DXGI Factory. (hr=0x%lX)", hr);
return VLC_EGENERIC;
}
hr = IDXGIFactory_CreateSwapChain(sys->dxgifactory, (IUnknown *)sys->d3ddevice, &scd, &sys->dxgiswapChain);
-
+ IDXGIFactory_Release(sys->dxgifactory);
if (FAILED(hr)) {
msg_Err(vd, "Could not create the SwapChain. (hr=0x%lX)", hr);
return VLC_EGENERIC;
@@ -783,6 +788,8 @@ static void Direct3D11Close(vout_display_t *vd)
vout_display_sys_t *sys = vd->sys;
Direct3D11DestroyResources(vd);
+ if (sys->dxgiswapChain)
+ IDXGISwapChain_Release(sys->dxgiswapChain);
if ( sys->d3dcontext )
ID3D11DeviceContext_Release(sys->d3dcontext);
if ( sys->d3ddevice )
@@ -886,6 +893,7 @@ static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
return VLC_EGENERIC;
}
ID3D11DeviceContext_VSSetShader(sys->d3dcontext, d3dvertexShader, NULL, 0);
+ ID3D11VertexShader_Release(d3dvertexShader);
D3D11_INPUT_ELEMENT_DESC layout[] = {
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
@@ -904,6 +912,7 @@ static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
}
ID3D11DeviceContext_IASetInputLayout(sys->d3dcontext, pVertexLayout);
+ ID3D11SamplerState_Release(pVertexLayout);
/* create the index of the vertices */
WORD indices[] = {
@@ -929,6 +938,8 @@ static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
return VLC_EGENERIC;
}
ID3D11DeviceContext_IASetIndexBuffer(sys->d3dcontext, pIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
+ ID3D11Buffer_Release(pIndexBuffer);
+
ID3D11DeviceContext_IASetPrimitiveTopology(sys->d3dcontext, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
ID3DBlob* pPSBlob = NULL;
@@ -1048,6 +1059,7 @@ static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
return VLC_EGENERIC;
}
ID3D11DeviceContext_PSSetSamplers(sys->d3dcontext, 0, 1, &d3dsampState);
+ ID3D11SamplerState_Release(d3dsampState);
picture_sys_t *picsys = malloc(sizeof(*picsys));
if (unlikely(picsys == NULL)) {
@@ -1069,6 +1081,7 @@ static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
free(picsys);
return VLC_ENOMEM;
}
+ ID3D11DeviceContext_AddRef(picsys->context);
sys->picsys = picsys;
picture_pool_configuration_t pool_cfg;
@@ -1096,9 +1109,14 @@ static void Direct3D11DestroyResources(vout_display_t *vd)
if (sys->pool) {
picture_sys_t *picsys = sys->picsys;
ID3D11Texture2D_Release(picsys->texture);
+ ID3D11DeviceContext_Release(picsys->context);
picture_pool_Release(sys->pool);
}
sys->pool = NULL;
+ if (sys->d3drenderTargetView)
+ ID3D11RenderTargetView_Release(sys->d3drenderTargetView);
+ if (sys->d3ddepthStencilView)
+ ID3D11DepthStencilView_Release(sys->d3ddepthStencilView);
msg_Dbg(vd, "Direct3D11 resources destroyed");
}
More information about the vlc-commits
mailing list