Browse Source

memory leak behoben

Kolja Strohm 5 years ago
parent
commit
e8f46e4958
1 changed files with 14 additions and 3 deletions
  1. 14 3
      DX12GraphicsApi.cpp

+ 14 - 3
DX12GraphicsApi.cpp

@@ -164,9 +164,9 @@ void DirectX12::initialize( WFenster * fenster, Vec2<int> backBufferSize, bool f
     }
     D3D12SerializeVersionedRootSignatureFunction d3d12svrsf = (D3D12SerializeVersionedRootSignatureFunction)GetProcAddress( d3d12DLL, "D3D12SerializeVersionedRootSignature" );
     D3D12SerializeRootSignatureFunction d3d12srsf = (D3D12SerializeRootSignatureFunction)GetProcAddress( d3d12DLL, "D3D12SerializeRootSignature" );
-#ifdef _DEBUG
     D3D12GetDebugInterfaceFunction getDebugInterface = (D3D12GetDebugInterfaceFunction)GetProcAddress( d3d12DLL, "D3D12GetDebugInterface" );
     getDebugInterface( __uuidof( ID3D12Debug ), (void **)& debug );
+#ifdef _DEBUG
     debug->EnableDebugLayer();
 #endif
     IDXGIFactory4 *factory;
@@ -192,12 +192,14 @@ void DirectX12::initialize( WFenster * fenster, Vec2<int> backBufferSize, bool f
         res = factory->EnumAdapters1( index++, &current );
         if( res == S_OK )
         {
+            ID3D12Device2 *device = 0;
             DXGI_ADAPTER_DESC1 dxgiAdapterDesc1;
             current->GetDesc1( &dxgiAdapterDesc1 );
             if( ( dxgiAdapterDesc1.Flags &DXGI_ADAPTER_FLAG_SOFTWARE ) == 0 &&
                 dxgiAdapterDesc1.DedicatedVideoMemory > maxVideoMemory &&
-                SUCCEEDED( createDevice( current, D3D_FEATURE_LEVEL_12_1, __uuidof( ID3D12Device2 ), 0 ) ) )
+                SUCCEEDED( createDevice( current, D3D_FEATURE_LEVEL_12_1, __uuidof( ID3D12Device2 ), (void**)&device ) ) )
             {
+                device->Release();
                 if( best )
                     best->Release();
                 best = current;
@@ -989,6 +991,12 @@ bool DirectX12::isAvailable()
         getDLLRegister()->releaseDLL( "d3d12.dll" );
         return 0;
     }
+    D3D12GetDebugInterfaceFunction getDebugInterface = (D3D12GetDebugInterfaceFunction)GetProcAddress( d3d12DLL, "D3D12GetDebugInterface" );
+    ID3D12Debug *debug = 0;
+    getDebugInterface( __uuidof( ID3D12Debug ), (void **)&debug );
+#ifdef _DEBUG
+    debug->EnableDebugLayer();
+#endif
     IDXGIFactory4 *factory;
     UINT createFactoryFlags = 0;
 #if defined(_DEBUG)
@@ -1010,11 +1018,14 @@ bool DirectX12::isAvailable()
         {
             DXGI_ADAPTER_DESC1 dxgiAdapterDesc1;
             current->GetDesc1( &dxgiAdapterDesc1 );
+            ID3D12Device2 *device = 0;
             if( ( dxgiAdapterDesc1.Flags &DXGI_ADAPTER_FLAG_SOFTWARE ) == 0 &&
-                SUCCEEDED( createDevice( current, D3D_FEATURE_LEVEL_12_1, __uuidof( ID3D12Device2 ), 0 ) ) )
+                SUCCEEDED( createDevice( current, D3D_FEATURE_LEVEL_12_1, __uuidof( ID3D12Device2 ), (void**)&device ) ) )
             {
+                device->Release();
                 current->Release();
                 factory->Release();
+                debug->Release();
                 getDLLRegister()->releaseDLL( "dxgi.dll" );
                 getDLLRegister()->releaseDLL( "d3d12.dll" );
                 return 1;