diff --git a/framework/platform/device-dx.cpp b/framework/platform/device-dx.cpp index 6fa9279..a2d93d5 100644 --- a/framework/platform/device-dx.cpp +++ b/framework/platform/device-dx.cpp @@ -18,6 +18,17 @@ namespace xna { } bool GraphicsDevice::Initialize(GameWindow& gameWindow) { + if (_factory) { + _factory->Release(); + _factory = nullptr; + } + + auto hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&_factory); + + if (FAILED(hr)) { + return false; + } + if (_blendState == nullptr) _blendState = BlendState::NonPremultiplied(); @@ -56,13 +67,9 @@ namespace xna { _swapChain->Initialize(gameWindow); if (!_swapChain->Apply()) - return false; + return false; - IDXGIFactory1* dxgiFactory = nullptr; - if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&dxgiFactory)) - return false; - - if FAILED(dxgiFactory->MakeWindowAssociation(gameWindow.WindowHandle(), DXGI_MWA_NO_ALT_ENTER)) + if FAILED(_factory->MakeWindowAssociation(gameWindow.WindowHandle(), DXGI_MWA_NO_ALT_ENTER)) return false; if (!_renderTarget2D) { diff --git a/framework/platform/device-dx.hpp b/framework/platform/device-dx.hpp index ec2fa6d..e0bf2ad 100644 --- a/framework/platform/device-dx.hpp +++ b/framework/platform/device-dx.hpp @@ -22,6 +22,11 @@ namespace xna { _context->Release(); _context = nullptr; } + + if (_factory) { + _factory->Release(); + _factory = nullptr; + } } virtual void Clear() override; @@ -61,6 +66,7 @@ namespace xna { public: ID3D11Device* _device{ nullptr }; ID3D11DeviceContext* _context{ nullptr }; + IDXGIFactory1* _factory = nullptr; private: unsigned int _createDeviceFlags{ 0 };