mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Revert screen mode config variables when change not accepted
When changing the screen width, height or refresh rate config variables to 0 or negative values, which are not allowed by the backend, automatically revert the config variables to the actual values again to ensure that the config variables stay in sync with the state of the window. This fixes the client crashing in the graphics settings when setting the screen width and height to 0 via the console, which causes a division by zero when calculating the aspect ratio.
This commit is contained in:
parent
516315e0e2
commit
86bf5424e3
|
@ -3943,7 +3943,7 @@ void CClient::SwitchWindowScreen(int Index)
|
||||||
g_Config.m_GfxScreenHeight = CurMode.m_WindowHeight;
|
g_Config.m_GfxScreenHeight = CurMode.m_WindowHeight;
|
||||||
g_Config.m_GfxScreenRefreshRate = CurMode.m_RefreshRate;
|
g_Config.m_GfxScreenRefreshRate = CurMode.m_RefreshRate;
|
||||||
|
|
||||||
Graphics()->Resize(g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight, g_Config.m_GfxScreenRefreshRate);
|
Graphics()->ResizeToScreen();
|
||||||
|
|
||||||
SetWindowParams(IsFullscreen, IsBorderless);
|
SetWindowParams(IsFullscreen, IsBorderless);
|
||||||
}
|
}
|
||||||
|
@ -4032,7 +4032,7 @@ void CClient::ConchainWindowResize(IConsole::IResult *pResult, void *pUserData,
|
||||||
pfnCallback(pResult, pCallbackUserData);
|
pfnCallback(pResult, pCallbackUserData);
|
||||||
if(pSelf->Graphics() && pResult->NumArguments())
|
if(pSelf->Graphics() && pResult->NumArguments())
|
||||||
{
|
{
|
||||||
pSelf->Graphics()->Resize(g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight, g_Config.m_GfxScreenRefreshRate);
|
pSelf->Graphics()->ResizeToScreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2664,15 +2664,15 @@ void CGraphics_Threaded::Move(int x, int y)
|
||||||
PropChangedListener();
|
PropChangedListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGraphics_Threaded::Resize(int w, int h, int RefreshRate)
|
bool CGraphics_Threaded::Resize(int w, int h, int RefreshRate)
|
||||||
{
|
{
|
||||||
#if defined(CONF_VIDEORECORDER)
|
#if defined(CONF_VIDEORECORDER)
|
||||||
if(IVideo::Current() && IVideo::Current()->IsRecording())
|
if(IVideo::Current() && IVideo::Current()->IsRecording())
|
||||||
return;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(WindowWidth() == w && WindowHeight() == h && RefreshRate == m_ScreenRefreshRate)
|
if(WindowWidth() == w && WindowHeight() == h && RefreshRate == m_ScreenRefreshRate)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
// if the size is changed manually, only set the window resize, a window size changed event is triggered anyway
|
// if the size is changed manually, only set the window resize, a window size changed event is triggered anyway
|
||||||
if(m_pBackend->ResizeWindow(w, h, RefreshRate))
|
if(m_pBackend->ResizeWindow(w, h, RefreshRate))
|
||||||
|
@ -2680,7 +2680,20 @@ void CGraphics_Threaded::Resize(int w, int h, int RefreshRate)
|
||||||
CVideoMode CurMode;
|
CVideoMode CurMode;
|
||||||
m_pBackend->GetCurrentVideoMode(CurMode, m_ScreenHiDPIScale, g_Config.m_GfxDesktopWidth, g_Config.m_GfxDesktopHeight, g_Config.m_GfxScreen);
|
m_pBackend->GetCurrentVideoMode(CurMode, m_ScreenHiDPIScale, g_Config.m_GfxDesktopWidth, g_Config.m_GfxDesktopHeight, g_Config.m_GfxScreen);
|
||||||
GotResized(w, h, RefreshRate);
|
GotResized(w, h, RefreshRate);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGraphics_Threaded::ResizeToScreen()
|
||||||
|
{
|
||||||
|
if(Resize(g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight, g_Config.m_GfxScreenRefreshRate))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Revert config variables if the change was not accepted
|
||||||
|
g_Config.m_GfxScreenWidth = ScreenWidth();
|
||||||
|
g_Config.m_GfxScreenHeight = ScreenHeight();
|
||||||
|
g_Config.m_GfxScreenRefreshRate = m_ScreenRefreshRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGraphics_Threaded::GotResized(int w, int h, int RefreshRate)
|
void CGraphics_Threaded::GotResized(int w, int h, int RefreshRate)
|
||||||
|
|
|
@ -1237,7 +1237,8 @@ public:
|
||||||
void SetWindowParams(int FullscreenMode, bool IsBorderless) override;
|
void SetWindowParams(int FullscreenMode, bool IsBorderless) override;
|
||||||
bool SetWindowScreen(int Index) override;
|
bool SetWindowScreen(int Index) override;
|
||||||
void Move(int x, int y) override;
|
void Move(int x, int y) override;
|
||||||
void Resize(int w, int h, int RefreshRate) override;
|
bool Resize(int w, int h, int RefreshRate) override;
|
||||||
|
void ResizeToScreen() override;
|
||||||
void GotResized(int w, int h, int RefreshRate) override;
|
void GotResized(int w, int h, int RefreshRate) override;
|
||||||
void UpdateViewport(int X, int Y, int W, int H, bool ByResize) override;
|
void UpdateViewport(int X, int Y, int W, int H, bool ByResize) override;
|
||||||
void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc) override;
|
void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc) override;
|
||||||
|
|
|
@ -295,7 +295,8 @@ public:
|
||||||
virtual bool SetMultiSampling(uint32_t ReqMultiSamplingCount, uint32_t &MultiSamplingCountBackend) = 0;
|
virtual bool SetMultiSampling(uint32_t ReqMultiSamplingCount, uint32_t &MultiSamplingCountBackend) = 0;
|
||||||
virtual int GetWindowScreen() = 0;
|
virtual int GetWindowScreen() = 0;
|
||||||
virtual void Move(int x, int y) = 0;
|
virtual void Move(int x, int y) = 0;
|
||||||
virtual void Resize(int w, int h, int RefreshRate) = 0;
|
virtual bool Resize(int w, int h, int RefreshRate) = 0;
|
||||||
|
virtual void ResizeToScreen() = 0;
|
||||||
virtual void GotResized(int w, int h, int RefreshRate) = 0;
|
virtual void GotResized(int w, int h, int RefreshRate) = 0;
|
||||||
virtual void UpdateViewport(int X, int Y, int W, int H, bool ByResize) = 0;
|
virtual void UpdateViewport(int X, int Y, int W, int H, bool ByResize) = 0;
|
||||||
|
|
||||||
|
|
|
@ -1567,7 +1567,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
|
||||||
g_Config.m_GfxScreenWidth = s_aModes[NewSelected].m_WindowWidth;
|
g_Config.m_GfxScreenWidth = s_aModes[NewSelected].m_WindowWidth;
|
||||||
g_Config.m_GfxScreenHeight = s_aModes[NewSelected].m_WindowHeight;
|
g_Config.m_GfxScreenHeight = s_aModes[NewSelected].m_WindowHeight;
|
||||||
g_Config.m_GfxScreenRefreshRate = s_aModes[NewSelected].m_RefreshRate;
|
g_Config.m_GfxScreenRefreshRate = s_aModes[NewSelected].m_RefreshRate;
|
||||||
Graphics()->Resize(g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight, g_Config.m_GfxScreenRefreshRate);
|
Graphics()->ResizeToScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
// switches
|
// switches
|
||||||
|
|
Loading…
Reference in a new issue