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 <yaka@microsoft.com>
This commit is contained in:
Yanna 2023-10-16 11:25:15 -07:00 committed by GitHub
parent 7c440b339f
commit d952e5cfb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -142,9 +142,9 @@ namespace bgfx
template<typename T> template<typename T>
static bool trySetSwapChain(IInspectable* nativeWindow, Dxgi::SwapChainI* swapChain, HRESULT* hr) 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) || NULL == swapChainPanelNative)
{ {
return false; return false;