Skip to content
Permalink
Browse files

Fix server crash on server-window resize

  • Loading branch information...
Necktrox committed Feb 12, 2018
1 parent c27fcaa commit becf0c27a4e06cf4fdec4251da7c40c1fd210c99
Showing with 9 additions and 4 deletions.
  1. +7 −3 Server/core/CServerImpl.cpp
  2. +2 −1 Server/core/CServerImpl.h
@@ -606,12 +606,11 @@ void CServerImpl::ShowInfoTag ( char* szTag )
// Windows console code
// Get the console's width
CONSOLE_SCREEN_BUFFER_INFO ScrnBufferInfo;

if ( !GetConsoleScreenBufferInfo( m_hConsole, &ScrnBufferInfo ) )
return;

COORD BufferSize = { ScrnBufferInfo.dwSize.X, 1 };
COORD TopLeft = { 0, ScrnBufferInfo.srWindow.Top };
SMALL_RECT Region = { 0, ScrnBufferInfo.srWindow.Top, ScrnBufferInfo.dwSize.X, 1 };
ScrnBufferInfo.dwSize.X = std::min ( ScrnBufferInfo.dwSize.X, SCREEN_BUFFER_SIZE );

// If the screenbuffer doesn't exist yet, or if the tag is changed
if ( m_ScrnBuffer == NULL || strcmp ( szTag, m_szTag ) )
@@ -657,6 +656,11 @@ void CServerImpl::ShowInfoTag ( char* szTag )
}
}
}

COORD BufferSize = { ScrnBufferInfo.dwSize.X, 1 };
COORD TopLeft = { 0, ScrnBufferInfo.srWindow.Top };
SMALL_RECT Region = { 0, ScrnBufferInfo.srWindow.Top, ScrnBufferInfo.dwSize.X, 1 };

WriteConsoleOutputW ( m_hConsole, m_ScrnBuffer, BufferSize, TopLeft, &Region);
#else
// Linux curses variant, so much easier :)
@@ -41,6 +41,7 @@ typedef CNetServer* (*InitNetServerInterface) ( void );

#ifdef WIN32
typedef void (FClientFeedback) ( const char* szText );
constexpr SHORT SCREEN_BUFFER_SIZE = 256;
#endif

class CServerImpl : public CServerInterface
@@ -110,7 +111,7 @@ class CServerImpl : public CServerInterface
#ifdef WIN32
HANDLE m_hConsole;
HANDLE m_hConsoleInput;
CHAR_INFO m_ScrnBuffer[256];
CHAR_INFO m_ScrnBuffer[SCREEN_BUFFER_SIZE];

CThreadCommandQueue* m_pThreadCommandQueue;
#endif

0 comments on commit becf0c2

Please sign in to comment.
You can’t perform that action at this time.