From a33fae19dd3b315c00185207edcff26bb9e93447 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sat, 4 May 2019 13:26:36 +0300 Subject: [PATCH] - improved handling of HUDMSG_TYPEON This includes the following changes * Validation of serialized values * Proper fix for message cut off after an empty line, part of https://forum.zdoom.org/viewtopic.php?t=63935, which appeared to be broken again with dbf06fc * No crash with an empty HUD message, https://forum.zdoom.org/viewtopic.php?t=63761 and https://forum.zdoom.org/viewtopic.php?t=64569 --- src/g_statusbar/hudmessages.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/g_statusbar/hudmessages.cpp b/src/g_statusbar/hudmessages.cpp index 27ec6a34a..c4ea1cf8d 100644 --- a/src/g_statusbar/hudmessages.cpp +++ b/src/g_statusbar/hudmessages.cpp @@ -737,8 +737,21 @@ void DHUDMessageTypeOnFadeOut::Serialize(FSerializer &arc) Super::Serialize (arc); arc("typeontime", TypeOnTime) ("currline", CurrLine) - ("linevisible", LineVisible) - ("linelen", LineLen); + ("linevisible", LineVisible); + + if (arc.isReading()) + { + if (CurrLine < NumLines) + { + LineLen = (int)Lines[CurrLine].Text.Len(); + } + else + { + LineLen = CurrLine = 0; + } + + clamp(LineVisible, 0, LineLen); + } } //============================================================================ @@ -749,7 +762,7 @@ void DHUDMessageTypeOnFadeOut::Serialize(FSerializer &arc) bool DHUDMessageTypeOnFadeOut::Tick () { - if (LineLen > 0 && !Super::Tick ()) + if (NumLines > 0 && !Super::Tick ()) { if (State == 3) { @@ -820,7 +833,7 @@ void DHUDMessageTypeOnFadeOut::ScreenSizeChanged () if (State == 3) { CurrLine = 0; - LineLen = Lines.Size() > 0 ? (int)Lines[0].Text.Len() : 0; + LineLen = NumLines > 0 ? (int)Lines[0].Text.Len() : 0; Tics = (int)(charCount * TypeOnTime) - 1; Tick (); }