mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-12-23 22:31:46 +00:00
[c-host] dxgi: fixed memory leak
This commit is contained in:
parent
79ce98116a
commit
f79a1b2533
1 changed files with 48 additions and 33 deletions
|
@ -128,14 +128,11 @@ static bool dxgi_init()
|
|||
for(int n = 0; IDXGIAdapter1_EnumOutputs(adapter, n, &output) != DXGI_ERROR_NOT_FOUND; ++n)
|
||||
{
|
||||
IDXGIOutput_GetDesc(output, &outputDesc);
|
||||
if (!outputDesc.AttachedToDesktop)
|
||||
{
|
||||
if (outputDesc.AttachedToDesktop)
|
||||
break;
|
||||
|
||||
IDXGIOutput_Release(output);
|
||||
output = NULL;
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (output)
|
||||
|
@ -148,7 +145,7 @@ static bool dxgi_init()
|
|||
if (!output)
|
||||
{
|
||||
DEBUG_ERROR("Failed to locate a valid output device");
|
||||
goto fail;
|
||||
goto fail_release_factory;
|
||||
}
|
||||
|
||||
static const D3D_FEATURE_LEVEL featureLevels[] =
|
||||
|
@ -249,6 +246,7 @@ static bool dxgi_init()
|
|||
IDXGIOutput1_Release(output1);
|
||||
goto fail_release_device;
|
||||
}
|
||||
IDXGIOutput1_Release(output1);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -286,6 +284,7 @@ static bool dxgi_init()
|
|||
IDXGIOutput5_Release(output5);
|
||||
goto fail_release_device;
|
||||
}
|
||||
IDXGIOutput5_Release(output5);
|
||||
}
|
||||
|
||||
DXGI_OUTDUPL_DESC dupDesc;
|
||||
|
@ -329,7 +328,7 @@ static bool dxgi_init()
|
|||
if (FAILED(status))
|
||||
{
|
||||
DEBUG_WINERROR("Failed to map the texture", status);
|
||||
goto fail_release_output;
|
||||
goto fail_release_texture;
|
||||
}
|
||||
this->pitch = mapping.RowPitch;
|
||||
this->stride = mapping.RowPitch / 4;
|
||||
|
@ -341,15 +340,21 @@ static bool dxgi_init()
|
|||
this->initialized = true;
|
||||
return true;
|
||||
|
||||
fail_release_texture:
|
||||
ID3D11Texture2D_Release(this->texture);
|
||||
this->texture = NULL;
|
||||
fail_release_output:
|
||||
IDXGIOutputDuplication_Release(this->dup);
|
||||
this->dup = NULL;
|
||||
fail_release_device:
|
||||
ID3D11Device_Release (this->device );
|
||||
ID3D11DeviceContext_Release(this->deviceContext);
|
||||
this->device = NULL;
|
||||
this->deviceContext = NULL;
|
||||
fail_release:
|
||||
IDXGIOutput_Release (output );
|
||||
IDXGIAdapter1_Release(adapter);
|
||||
fail_release_factory:
|
||||
IDXGIFactory1_Release(factory);
|
||||
fail:
|
||||
return false;
|
||||
|
@ -359,8 +364,6 @@ static bool dxgi_deinit()
|
|||
{
|
||||
assert(this);
|
||||
|
||||
os_signalEvent(this->copyEvent);
|
||||
|
||||
if (this->texture)
|
||||
{
|
||||
ID3D11Texture2D_Release(this->texture);
|
||||
|
@ -374,10 +377,10 @@ static bool dxgi_deinit()
|
|||
this->dup = NULL;
|
||||
}
|
||||
|
||||
if (this->device)
|
||||
if (this->deviceContext)
|
||||
{
|
||||
ID3D11Device_Release(this->device);
|
||||
this->device = NULL;
|
||||
ID3D11DeviceContext_Release(this->deviceContext);
|
||||
this->deviceContext = NULL;
|
||||
}
|
||||
|
||||
if (this->output)
|
||||
|
@ -386,6 +389,12 @@ static bool dxgi_deinit()
|
|||
this->output = NULL;
|
||||
}
|
||||
|
||||
if (this->device)
|
||||
{
|
||||
ID3D11Device_Release(this->device);
|
||||
this->device = NULL;
|
||||
}
|
||||
|
||||
if (this->adapter)
|
||||
{
|
||||
IDXGIAdapter1_Release(this->adapter);
|
||||
|
@ -394,8 +403,14 @@ static bool dxgi_deinit()
|
|||
|
||||
if (this->factory)
|
||||
{
|
||||
IDXGIFactory1_Release(this->factory);
|
||||
// if this doesn't free we have a memory leak
|
||||
DWORD count = IDXGIFactory1_Release(this->factory);
|
||||
this->factory = NULL;
|
||||
if (count != 0)
|
||||
{
|
||||
DEBUG_ERROR("Factory release is %lu, there is a memory leak!", count);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
this->initialized = false;
|
||||
|
@ -456,6 +471,8 @@ static CaptureResult dxgi_capture(bool * hasFrameUpdate, bool * hasPointerUpdate
|
|||
return CAPTURE_RESULT_ERROR;
|
||||
}
|
||||
|
||||
if (frameInfo.LastPresentTime.QuadPart != 0)
|
||||
{
|
||||
ID3D11Texture2D * src;
|
||||
status = IDXGIResource_QueryInterface(res, &IID_ID3D11Texture2D, (void **)&src);
|
||||
if (FAILED(status))
|
||||
|
@ -465,8 +482,6 @@ static CaptureResult dxgi_capture(bool * hasFrameUpdate, bool * hasPointerUpdate
|
|||
return CAPTURE_RESULT_ERROR;
|
||||
}
|
||||
|
||||
if (frameInfo.LastPresentTime.QuadPart != 0)
|
||||
{
|
||||
// wait for the prior copy to finish in getFrame
|
||||
os_waitEvent(this->copyEvent);
|
||||
|
||||
|
|
Loading…
Reference in a new issue