Repository: microsoft/terminal (language: cpp)

Issue:
Renderer encountered an unexpected error: -2005270483
### Windows Terminal version

main b4d37d8c7

### Windows build number

10.0.22621.169 (aarch64)

### Other Software

_No response_

### Steps to reproduce

- build latest source on Windows `aarch64` (Windows DevKit 2023 used for testing)

### Expected Behavior

- terminal to launch

### Actual Behavior

Error message: `This terminal has encountered an issue with the graphics driver and it could not recover in time. It has been suspended.`

Upon pressing `Resume` an error is thrown:

![Screenshot 2022-10-31 190138](https://user-images.githubusercontent.com/3933920/199143388-924c2e93-34ed-4baf-9806-653c09e4aeca.png)



Discussion / hints:
I can repro this on my volterra too. 

Error Code | Symbolic Name | Error Description | Header
-- | -- | -- | --
0x887a002d | -2005270483 | DXGI_ERROR_SDK_COMPONENT_MISSING | The application requested an operation that depends on an SDK component that is missing or mismatched. | winerror.h

If you run a debug build you'll need to install the DirectX SDK. It should be part of the "Graphics debugger and GPU profiler for DirectX" component in the Visual Studio Installer. It happens because this isn't true and doesn't work: https://github.com/microsoft/terminal/blob/b4d37d8c70b02952ffed9715bd10893e688024a8/src/renderer/atlas/AtlasEngine.cpp#L551-L552

If anyone wants to fix this, please do so! I just didn't have the time to set up a VM and test this just yet, especially since I personally always have the SDK installed for debugging purposes.

Edit: I changed the title so that this issue is easier to find.

Fix patch:
diff --git a/src/renderer/atlas/AtlasEngine.r.cpp b/src/renderer/atlas/AtlasEngine.r.cpp
index 7b4fc1885f4..717516c9cf5 100644
--- a/src/renderer/atlas/AtlasEngine.r.cpp
+++ b/src/renderer/atlas/AtlasEngine.r.cpp
@@ -120,8 +120,20 @@ void AtlasEngine::_recreateAdapter()
     static constexpr UINT flags = 0;
 #endif
 
-    // IID_PPV_ARGS doesn't work here for some reason.
-    THROW_IF_FAILED(CreateDXGIFactory2(flags, __uuidof(_p.dxgi.factory), _p.dxgi.factory.put_void()));
+// IID_PPV_ARGS doesn't work here for some reason.
+#pragma warning(suppress : 26496) // The variable 'hr' does not change after construction, mark it as const (con.4).
+    auto hr = CreateDXGIFactory2(flags, __uuidof(_p.dxgi.factory), _p.dxgi.factory.put_void());
+
+#ifndef NDEBUG
+    // This might be due to missing the "Graphics debugger and GPU profiler for
+    // DirectX" tools. Just as a sanity check, try again without
+    // `DXGI_CREATE_FACTORY_DEBUG`
+    if (FAILED(hr))
+    {
+        hr = CreateDXGIFactory2(0, __uuidof(_p.dxgi.factory), _p.dxgi.factory.put_void());
+    }
+#endif
+    THROW_IF_FAILED(hr);
 
     wil::com_ptr<IDXGIAdapter1> adapter;
     DXGI_ADAPTER_DESC1 desc{};
@@ -189,7 +201,8 @@ void AtlasEngine::_recreateBackend()
         D3D_FEATURE_LEVEL_9_1,
     };
 
-    THROW_IF_FAILED(D3D11CreateDevice(
+#pragma warning(suppress : 26496) // The variable 'hr' does not change after construction, mark it as const (con.4).
+    auto hr = D3D11CreateDevice(
         /* pAdapter */ _p.dxgi.adapter.get(),
         /* DriverType */ D3D_DRIVER_TYPE_UNKNOWN,
         /* Software */ nullptr,
@@ -199,7 +212,30 @@ void AtlasEngine::_recreateBackend()
         /* SDKVersion */ D3D11_SDK_VERSION,
         /* ppDevice */ device0.put(),
         /* pFeatureLevel */ &featureLevel,
-        /* ppImmediateContext */ deviceContext0.put()));
+        /* ppImmediateContext */ deviceContext0.put());
+
+#ifndef NDEBUG
+    if (hr == DXGI_ERROR_SDK_COMPONENT_MISSING)
+    {
+        // This might happen if you don't have "Graphics debugger and GPU
+        // profiler for DirectX" installed in VS. We shouln't just explode if
+        // you don't though - instead, disable debugging and try again.
+        WI_ClearFlag(deviceFlags, D3D11_CREATE_DEVICE_DEBUG);
+
+        hr = D3D11CreateDevice(
+            /* pAdapter */ _p.dxgi.adapter.get(),
+            /* DriverType */ D3D_DRIVER_TYPE_UNKNOWN,
+            /* Software */ nullptr,
+            /* Flags */ deviceFlags,
+            /* pFeatureLevels */ featureLevels.data(),
+            /* FeatureLevels */ gsl::narrow_cast<UINT>(featureLevels.size()),
+            /* SDKVersion */ D3D11_SDK_VERSION,
+            /* ppDevice */ device0.put(),
+            /* pFeatureLevel */ &featureLevel,
+            /* ppImmediateContext */ deviceContext0.put());
+    }
+#endif
+    THROW_IF_FAILED(hr);
 
     auto device = device0.query<ID3D11Device2>();
     auto deviceContext = deviceContext0.query<ID3D11DeviceContext2>();


Test patch: