Skip to content

Commit

Permalink
Fixed game window doesn't hide on fatal crash
Browse files Browse the repository at this point in the history
Thanks to @Hrusteckiy for reminding me about the bug until I made this commit.
  • Loading branch information
Xottab-DUTY committed Dec 13, 2022
1 parent ad9dfd0 commit 588feb3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/xrCore/xrDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,10 @@ AssertionResult xrDebug::Fail(bool& ignoreAlways, const ErrorLocation& loc, cons
#ifdef USE_BUG_TRAP
BT_SetUserMessage(assertionInfo);
#endif
// calling DEBUG_BREAK with no debugger will trigger BugTrap
// we must hide the window
if (windowHandler && !DebuggerIsPresent())
windowHandler->OnFatalError();
DEBUG_BREAK;
} // switch (result)
}
Expand Down Expand Up @@ -575,6 +579,9 @@ void xrDebug::DoExit(const std::string& message)
else
ShowMessage(Core.ApplicationName, message.c_str());

if (windowHandler)
windowHandler->OnFatalError();

#if defined(XR_PLATFORM_WINDOWS)
TerminateProcess(GetCurrentProcess(), 1);
#else
Expand Down Expand Up @@ -821,7 +828,11 @@ LONG WINAPI xrDebug::UnhandledFilter(EXCEPTION_POINTERS* exPtrs)

// Typically, PrevFilter is BugTrap filter
if (PrevFilter)
{
if (windowHandler)
windowHandler->OnFatalError();
PrevFilter(exPtrs);
}

if (windowHandler)
windowHandler->OnErrorDialog(false);
Expand Down
1 change: 1 addition & 0 deletions src/xrCore/xrDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class IWindowHandler
virtual ~IWindowHandler() = default;
virtual SDL_Window* GetApplicationWindow() = 0;
virtual void OnErrorDialog(bool beforeDialog) = 0;
virtual void OnFatalError() = 0;
};

class IUserConfigHandler
Expand Down
12 changes: 12 additions & 0 deletions src/xrEngine/Device_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,15 @@ void CRenderDevice::OnErrorDialog(bool beforeDialog)
if (needUpdateInput)
pInput->GrabInput(restore);
}

void CRenderDevice::OnFatalError()
{
// make it sure window will hide in any way
SDL_SetWindowFullscreen(m_sdlWnd, SDL_FALSE);
#if SDL_VERSION_ATLEAST(2, 0, 16)
SDL_SetWindowAlwaysOnTop(m_sdlWnd, SDL_FALSE);
#endif
SDL_ShowWindow(m_sdlWnd);
SDL_MinimizeWindow(m_sdlWnd);
SDL_HideWindow(m_sdlWnd);
}
1 change: 1 addition & 0 deletions src/xrEngine/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class ENGINE_API CRenderDevice : public CRenderDeviceData, public IWindowHandler

SDL_Window* GetApplicationWindow() override;
void OnErrorDialog(bool beforeDialog) override;
void OnFatalError() override;

void time_factor(const float time_factor);

Expand Down

0 comments on commit 588feb3

Please sign in to comment.