fix memory leaks
This commit is contained in:
parent
a25597223d
commit
04475c3c37
|
|
@ -269,21 +269,6 @@ void WindowWin32Impl::Init(const String& title, uint32_t width, uint32_t height,
|
||||||
|
|
||||||
::ShowWindow(handle_, SW_SHOWNORMAL);
|
::ShowWindow(handle_, SW_SHOWNORMAL);
|
||||||
::UpdateWindow(handle_);
|
::UpdateWindow(handle_);
|
||||||
|
|
||||||
// Initialize Direct3D resources
|
|
||||||
auto d3d_res = graphics::directx::GetD3DDeviceResources();
|
|
||||||
|
|
||||||
HRESULT hr = d3d_res->Initialize(handle_);
|
|
||||||
|
|
||||||
// Initialize Direct2D resources
|
|
||||||
if (SUCCEEDED(hr))
|
|
||||||
{
|
|
||||||
auto d2d_res = graphics::directx::GetD2DDeviceResources();
|
|
||||||
|
|
||||||
hr = d2d_res->Initialize(d3d_res->GetDXGIDevice(), d3d_res->GetDXGISwapChain());
|
|
||||||
}
|
|
||||||
|
|
||||||
KGE_THROW_IF_FAILED(hr, "Create DirectX resources failed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowWin32Impl::PumpEvents()
|
void WindowWin32Impl::PumpEvents()
|
||||||
|
|
|
||||||
|
|
@ -58,11 +58,41 @@ void RendererImpl::MakeContextForWindow(WindowPtr window)
|
||||||
HWND target_window = window->GetHandle();
|
HWND target_window = window->GetHandle();
|
||||||
output_size_ = window->GetSize();
|
output_size_ = window->GetSize();
|
||||||
|
|
||||||
d2d_res_ = graphics::directx::GetD2DDeviceResources();
|
|
||||||
d3d_res_ = graphics::directx::GetD3DDeviceResources();
|
|
||||||
|
|
||||||
HRESULT hr = target_window ? S_OK : E_FAIL;
|
HRESULT hr = target_window ? S_OK : E_FAIL;
|
||||||
|
|
||||||
|
// Initialize Direct3D resources
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
auto d3d_res = graphics::directx::GetD3DDeviceResources();
|
||||||
|
|
||||||
|
hr = d3d_res->Initialize(target_window);
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
d3d_res->DiscardResources();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
d3d_res_ = d3d_res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize Direct2D resources
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
auto d2d_res = graphics::directx::GetD2DDeviceResources();
|
||||||
|
|
||||||
|
hr = d2d_res->Initialize(d3d_res_->GetDXGIDevice(), d3d_res_->GetDXGISwapChain());
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
d2d_res->DiscardResources();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
d2d_res_ = d2d_res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Initialize other device resources
|
// Initialize other device resources
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
|
|
@ -114,15 +144,23 @@ void RendererImpl::Destroy()
|
||||||
{
|
{
|
||||||
KGE_SYS_LOG("Destroying device resources");
|
KGE_SYS_LOG("Destroying device resources");
|
||||||
|
|
||||||
d2d_res_->GetDWriteFactory()->UnregisterFontFileLoader(res_font_file_loader_.Get());
|
if (d2d_res_)
|
||||||
res_font_file_loader_.Reset();
|
{
|
||||||
|
d2d_res_->GetDWriteFactory()->UnregisterFontFileLoader(res_font_file_loader_.Get());
|
||||||
|
res_font_file_loader_.Reset();
|
||||||
|
|
||||||
d2d_res_->GetDWriteFactory()->UnregisterFontCollectionLoader(res_font_collection_loader_.Get());
|
d2d_res_->GetDWriteFactory()->UnregisterFontCollectionLoader(res_font_collection_loader_.Get());
|
||||||
res_font_collection_loader_.Reset();
|
res_font_collection_loader_.Reset();
|
||||||
|
|
||||||
render_ctx_.Reset();
|
render_ctx_.Reset();
|
||||||
d2d_res_.Reset();
|
d2d_res_->DiscardResources();
|
||||||
d3d_res_.Reset();
|
}
|
||||||
|
|
||||||
|
if (d3d_res_)
|
||||||
|
{
|
||||||
|
d3d_res_->DiscardResources();
|
||||||
|
d3d_res_.Reset();
|
||||||
|
}
|
||||||
|
|
||||||
::CoUninitialize();
|
::CoUninitialize();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue