Compare commits

...

5 Commits

Author SHA1 Message Date
Dennis Felsing d265057591
Merge pull request #8278 from Robyt3/Client-Move-Resize-Fixes
Revert screen mode config variables when change not accepted, update screen index config variable after moving window
2024-04-28 15:18:16 +00:00
Dennis Felsing b3bd831cde
Merge pull request #8279 from Robyt3/Base-FutureLogger-Leak
Add no-op logger to fix leak of `CFutureLogger` pending messages
2024-04-28 15:17:53 +00:00
Robert Müller b3bcfd39bc Add no-op logger to fix leak of `CFutureLogger` pending messages
Fix leak of pending future logger log messages if the future logger is not set, in particular when the `logfile` config variable is not set or the file could not be opened, by setting a logger that discards all log messages in this case.

Closes #8265.
2024-04-28 16:32:24 +02:00
Robert Müller e4dddb95ce Update screen index config variable after moving window
The wrong screen was shown in the settings when moving the window to another screen while in windowed mode.
2024-04-28 15:29:05 +02:00
Robert Müller 86bf5424e3 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.
2024-04-28 15:25:31 +02:00
9 changed files with 61 additions and 12 deletions

View File

@ -483,6 +483,19 @@ std::unique_ptr<ILogger> log_logger_windows_debugger()
}
#endif
class CLoggerNoOp : public ILogger
{
public:
void Log(const CLogMessage *pMessage) override
{
// no-op
}
};
std::unique_ptr<ILogger> log_logger_noop()
{
return std::make_unique<CLoggerNoOp>();
}
void CFutureLogger::Set(std::shared_ptr<ILogger> pLogger)
{
const CLockScope LockScope(m_PendingLock);

View File

@ -210,6 +210,13 @@ std::unique_ptr<ILogger> log_logger_stdout();
*/
std::unique_ptr<ILogger> log_logger_windows_debugger();
/**
* @ingroup Log
*
* Logger which discards all logs.
*/
std::unique_ptr<ILogger> log_logger_noop();
/**
* @ingroup Log
*

View File

@ -1539,6 +1539,7 @@ bool CGraphicsBackend_SDL_GL::UpdateDisplayMode(int Index)
return false;
}
g_Config.m_GfxScreen = Index;
g_Config.m_GfxDesktopWidth = DisplayMode.w;
g_Config.m_GfxDesktopHeight = DisplayMode.h;

View File

@ -3929,8 +3929,10 @@ void CClient::SwitchWindowScreen(int Index)
int IsFullscreen = g_Config.m_GfxFullscreen;
int IsBorderless = g_Config.m_GfxBorderless;
if(Graphics()->SetWindowScreen(Index))
g_Config.m_GfxScreen = Index;
if(!Graphics()->SetWindowScreen(Index))
{
return;
}
SetWindowParams(3, false); // prevent DDNet to get stretch on monitors
@ -3943,7 +3945,7 @@ void CClient::SwitchWindowScreen(int Index)
g_Config.m_GfxScreenHeight = CurMode.m_WindowHeight;
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);
}
@ -4032,7 +4034,7 @@ void CClient::ConchainWindowResize(IConsole::IResult *pResult, void *pUserData,
pfnCallback(pResult, pCallbackUserData);
if(pSelf->Graphics() && pResult->NumArguments())
{
pSelf->Graphics()->Resize(g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight, g_Config.m_GfxScreenRefreshRate);
pSelf->Graphics()->ResizeToScreen();
}
}
@ -4499,9 +4501,9 @@ int main(int argc, const char **argv)
pSteam->ClearConnectAddress();
}
const int Mode = g_Config.m_Logappend ? IOFLAG_APPEND : IOFLAG_WRITE;
if(g_Config.m_Logfile[0])
{
const int Mode = g_Config.m_Logappend ? IOFLAG_APPEND : IOFLAG_WRITE;
IOHANDLE Logfile = pStorage->OpenFile(g_Config.m_Logfile, Mode, IStorage::TYPE_SAVE_OR_ABSOLUTE);
if(Logfile)
{
@ -4510,8 +4512,13 @@ int main(int argc, const char **argv)
else
{
log_error("client", "failed to open '%s' for logging", g_Config.m_Logfile);
pFutureFileLogger->Set(log_logger_noop());
}
}
else
{
pFutureFileLogger->Set(log_logger_noop());
}
// Register protocol and file extensions
#if defined(CONF_FAMILY_WINDOWS)

View File

@ -2664,15 +2664,15 @@ void CGraphics_Threaded::Move(int x, int y)
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(IVideo::Current() && IVideo::Current()->IsRecording())
return;
return false;
#endif
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(m_pBackend->ResizeWindow(w, h, RefreshRate))
@ -2680,7 +2680,20 @@ void CGraphics_Threaded::Resize(int w, int h, int RefreshRate)
CVideoMode CurMode;
m_pBackend->GetCurrentVideoMode(CurMode, m_ScreenHiDPIScale, g_Config.m_GfxDesktopWidth, g_Config.m_GfxDesktopHeight, g_Config.m_GfxScreen);
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)

View File

@ -1237,7 +1237,8 @@ public:
void SetWindowParams(int FullscreenMode, bool IsBorderless) override;
bool SetWindowScreen(int Index) 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 UpdateViewport(int X, int Y, int W, int H, bool ByResize) override;
void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc) override;

View File

@ -295,7 +295,8 @@ public:
virtual bool SetMultiSampling(uint32_t ReqMultiSamplingCount, uint32_t &MultiSamplingCountBackend) = 0;
virtual int GetWindowScreen() = 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 UpdateViewport(int X, int Y, int W, int H, bool ByResize) = 0;

View File

@ -170,9 +170,9 @@ int main(int argc, const char **argv)
pConfigManager->SetReadOnly("sv_test_cmds", true);
pConfigManager->SetReadOnly("sv_rescue", true);
const int Mode = g_Config.m_Logappend ? IOFLAG_APPEND : IOFLAG_WRITE;
if(g_Config.m_Logfile[0])
{
const int Mode = g_Config.m_Logappend ? IOFLAG_APPEND : IOFLAG_WRITE;
IOHANDLE Logfile = pStorage->OpenFile(g_Config.m_Logfile, Mode, IStorage::TYPE_SAVE_OR_ABSOLUTE);
if(Logfile)
{
@ -181,8 +181,14 @@ int main(int argc, const char **argv)
else
{
log_error("server", "failed to open '%s' for logging", g_Config.m_Logfile);
pFutureFileLogger->Set(log_logger_noop());
}
}
else
{
pFutureFileLogger->Set(log_logger_noop());
}
auto pServerLogger = std::make_shared<CServerLogger>(pServer);
pEngine->SetAdditionalLogger(pServerLogger);

View File

@ -1567,7 +1567,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
g_Config.m_GfxScreenWidth = s_aModes[NewSelected].m_WindowWidth;
g_Config.m_GfxScreenHeight = s_aModes[NewSelected].m_WindowHeight;
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