Fix rare crash on Dear ImGui shutdown

Fix a rare crash that occurs in AMD driver code, when ImGui shutdown was called. The crash did not occur if the library was shutdown after having rendered one of the ImGui panels for one frame. The fix is to just never call 'ImGui_ImplDX11_NewFrame()', 'ImGui_ImplWin32_NewFrame()' and 'ImGui::NewFrame()', 'ImGui::EndFrame()', 'ImGui::Render()' if none of the windows are visible. code has been tested on a system that would trigger the crash, and after the patch, the crash no longer happened.
This commit is contained in:
Kawe Mazidjatari 2023-06-15 21:33:37 +02:00
parent 51ea9c7c4f
commit 48c2401cf9
3 changed files with 25 additions and 17 deletions

View File

@ -36,6 +36,8 @@ public:
void SetHostName(const char* pszHostName);
virtual void SetStyleVar(void);
inline bool IsVisible() { return m_flFadeAlpha > 0.0f; }
const char* m_pszBrowserLabel;
bool m_bActivate;

View File

@ -54,6 +54,8 @@ public:
vector<string> GetHistory(void) const;
void ClearHistory(void);
inline bool IsVisible() { return m_flFadeAlpha > 0.0f; }
private: // Internal only.
void AddLog(const ImVec4& color, const char* fmt, ...) /*IM_FMTARGS(2)*/;

View File

@ -97,28 +97,32 @@ void SetupImGui()
void DrawImGui()
{
ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();
// Only render if the ImGui panels are visible.
if (g_pBrowser->IsVisible() || g_pConsole->IsVisible())
{
ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
ImGui::NewFrame();
// This is required to disable the ctrl+tab menu as some users use this shortcut for other things in-game.
// See https://github.com/ocornut/imgui/issues/5641 for more details.
if (GImGui->ConfigNavWindowingKeyNext)
ImGui::SetShortcutRouting(GImGui->ConfigNavWindowingKeyNext, ImGuiKeyOwner_None);
if (GImGui->ConfigNavWindowingKeyPrev)
ImGui::SetShortcutRouting(GImGui->ConfigNavWindowingKeyPrev, ImGuiKeyOwner_None);
// This is required to disable the ctrl+tab menu as some users use this shortcut for other things in-game.
// See https://github.com/ocornut/imgui/issues/5641 for more details.
if (GImGui->ConfigNavWindowingKeyNext)
ImGui::SetShortcutRouting(GImGui->ConfigNavWindowingKeyNext, ImGuiKeyOwner_None);
if (GImGui->ConfigNavWindowingKeyPrev)
ImGui::SetShortcutRouting(GImGui->ConfigNavWindowingKeyPrev, ImGuiKeyOwner_None);
g_pBrowser->RunFrame();
g_pConsole->RunFrame();
ImGui::EndFrame();
ImGui::Render();
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
}
g_pBrowser->RunTask();
g_pConsole->RunTask();
g_pBrowser->RunFrame();
g_pConsole->RunFrame();
ImGui::EndFrame();
ImGui::Render();
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
}
//#################################################################################