Fix ImGui window procedure handler crash on shutdown

When and after 'Host_Shutdown()' is called, the window handle is still valid, thus the handler still gets called. This gets destroyed in 'OnShutdown()' called from 'CEngineAPI::RunListenServer()'. But we do shutdown the ImGui implementation in 'Host_Shutdown()'... Therefore, we should check if the implementation is initialized or not before running the window procedure handler.
This commit is contained in:
Kawe Mazidjatari 2023-06-19 14:03:23 +02:00
parent abe68def03
commit a9338455aa
3 changed files with 11 additions and 6 deletions

View File

@ -27,6 +27,9 @@ void CGame::PlayStartupVideos(void)
//-----------------------------------------------------------------------------
int CGame::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (!g_bImGuiInitialized)
return v_CGame__WindowProc(hWnd, uMsg, wParam, lParam);
ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam);
if (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN)

View File

@ -31,7 +31,8 @@ typedef BOOL(WINAPI* IPostMessageA)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM l
typedef BOOL(WINAPI* IPostMessageW)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
///////////////////////////////////////////////////////////////////////////////////
static BOOL s_bInitialized = FALSE;
extern BOOL g_bImGuiInitialized = FALSE;
extern UINT g_nWindowRect[2] = { NULL, NULL };
///////////////////////////////////////////////////////////////////////////////////
static IPostMessageA s_oPostMessageA = NULL;
@ -131,11 +132,11 @@ void DrawImGui()
HRESULT __stdcall Present(IDXGISwapChain* pSwapChain, UINT nSyncInterval, UINT nFlags)
{
if (!s_bInitialized)
if (!g_bImGuiInitialized)
{
ImGui_Init();
g_ThreadRenderThreadID = GetCurrentThreadId();
s_bInitialized = true;
g_bImGuiInitialized = true;
}
DrawImGui();
@ -385,10 +386,10 @@ void DirectX_Shutdown()
///////////////////////////////////////////////////////////////////////////////
// Shutdown ImGui
if (s_bInitialized)
if (g_bImGuiInitialized)
{
ImGui_Shutdown();
s_bInitialized = false;
g_bImGuiInitialized = false;
}
}

View File

@ -22,7 +22,8 @@ typedef HRESULT(__stdcall* IDXGIResizeBuffers) (IDXGISwapChain* pSwapChain, UI
/////////////////////////////////////////////////////////////////////////////
// Globals
inline UINT g_nWindowRect[2];
extern BOOL g_bImGuiInitialized;
extern UINT g_nWindowRect[2];
/////////////////////////////////////////////////////////////////////////////
// Enums