From d952e5cfb350dc01bb95bde833e453fa2a34b726 Mon Sep 17 00:00:00 2001 From: Yanna Date: Mon, 16 Oct 2023 11:25:15 -0700 Subject: [PATCH] Check nativeWindow pointer before dereferencing (#3185) Fix access violation in headless mode during bgfx::shutdown(). This pointer is usually set by the SwapChainPanel which doesn't exist in headless mode. Co-authored-by: Yanna Kang --- src/dxgi.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dxgi.cpp b/src/dxgi.cpp index 6871e1167..ecca128b2 100644 --- a/src/dxgi.cpp +++ b/src/dxgi.cpp @@ -142,9 +142,9 @@ namespace bgfx template static bool trySetSwapChain(IInspectable* nativeWindow, Dxgi::SwapChainI* swapChain, HRESULT* hr) { - ISwapChainPanelNative* swapChainPanelNative; + ISwapChainPanelNative* swapChainPanelNative = NULL; - if (FAILED(nativeWindow->QueryInterface(__uuidof(T), (void**)&swapChainPanelNative)) + if (NULL != nativeWindow && FAILED(nativeWindow->QueryInterface(__uuidof(T), (void**)&swapChainPanelNative)) || NULL == swapChainPanelNative) { return false;