From 30c2524742ae3ef8da3c8ee73fab9ce6b562cf1d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 14 Sep 2023 16:45:06 +0200 Subject: [PATCH] - validate text data before drawing the console. --- src/common/console/c_console.cpp | 69 +++++++++++++++++--------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/src/common/console/c_console.cpp b/src/common/console/c_console.cpp index f6366d7cd85..b6377f1f14b 100644 --- a/src/common/console/c_console.cpp +++ b/src/common/console/c_console.cpp @@ -648,48 +648,51 @@ void C_DrawConsole () conbuffer->FormatText(CurrentConsoleFont, ConWidth / textScale); unsigned int consolelines = conbuffer->GetFormattedLineCount(); FBrokenLines *blines = conbuffer->GetLines(); - FBrokenLines *printline = blines + consolelines - 1 - RowAdjust; - - int bottomline = ConBottom / textScale - CurrentConsoleFont->GetHeight()*2 - 4; - - for(FBrokenLines *p = printline; p >= blines && lines > 0; p--, lines--) + if (blines != nullptr) { - if (textScale == 1) - { - DrawText(twod, CurrentConsoleFont, CR_TAN, LEFTMARGIN, offset + lines * CurrentConsoleFont->GetHeight(), p->Text, TAG_DONE); - } - else - { - DrawText(twod, CurrentConsoleFont, CR_TAN, LEFTMARGIN, offset + lines * CurrentConsoleFont->GetHeight(), p->Text, - DTA_VirtualWidth, twod->GetWidth() / textScale, - DTA_VirtualHeight, twod->GetHeight() / textScale, - DTA_KeepRatio, true, TAG_DONE); - } - } + FBrokenLines* printline = blines + consolelines - 1 - RowAdjust; - if (ConBottom >= 20) - { - if (gamestate != GS_STARTUP) + int bottomline = ConBottom / textScale - CurrentConsoleFont->GetHeight() * 2 - 4; + + for (FBrokenLines* p = printline; p >= blines && lines > 0; p--, lines--) { - auto now = I_msTime(); - if (now > CursorTicker) + if (textScale == 1) { - CursorTicker = now + 500; - cursoron = !cursoron; + DrawText(twod, CurrentConsoleFont, CR_TAN, LEFTMARGIN, offset + lines * CurrentConsoleFont->GetHeight(), p->Text, TAG_DONE); } - CmdLine.Draw(left, bottomline, textScale, cursoron); - } - if (RowAdjust && ConBottom >= CurrentConsoleFont->GetHeight()*7/2) - { - // Indicate that the view has been scrolled up (10) - // and if we can scroll no further (12) - if (textScale == 1) - DrawChar(twod, CurrentConsoleFont, CR_GREEN, 0, bottomline, RowAdjust == conbuffer->GetFormattedLineCount() ? 12 : 10, TAG_DONE); else - DrawChar(twod, CurrentConsoleFont, CR_GREEN, 0, bottomline, RowAdjust == conbuffer->GetFormattedLineCount() ? 12 : 10, + { + DrawText(twod, CurrentConsoleFont, CR_TAN, LEFTMARGIN, offset + lines * CurrentConsoleFont->GetHeight(), p->Text, DTA_VirtualWidth, twod->GetWidth() / textScale, DTA_VirtualHeight, twod->GetHeight() / textScale, DTA_KeepRatio, true, TAG_DONE); + } + } + + if (ConBottom >= 20) + { + if (gamestate != GS_STARTUP) + { + auto now = I_msTime(); + if (now > CursorTicker) + { + CursorTicker = now + 500; + cursoron = !cursoron; + } + CmdLine.Draw(left, bottomline, textScale, cursoron); + } + if (RowAdjust && ConBottom >= CurrentConsoleFont->GetHeight() * 7 / 2) + { + // Indicate that the view has been scrolled up (10) + // and if we can scroll no further (12) + if (textScale == 1) + DrawChar(twod, CurrentConsoleFont, CR_GREEN, 0, bottomline, RowAdjust == conbuffer->GetFormattedLineCount() ? 12 : 10, TAG_DONE); + else + DrawChar(twod, CurrentConsoleFont, CR_GREEN, 0, bottomline, RowAdjust == conbuffer->GetFormattedLineCount() ? 12 : 10, + DTA_VirtualWidth, twod->GetWidth() / textScale, + DTA_VirtualHeight, twod->GetHeight() / textScale, + DTA_KeepRatio, true, TAG_DONE); + } } } }