TWP: ignore empty text lines

The SayLineAt class assumes that lines are non-empty strings and
accesses the first line character liberally. There is however at least
one instance of an empty line returned by the game script that causes
the engine to crash:

    saylineAt: (160,85) text=@25923 color=rgba(1.000000,0.800000,0.000000,1.000000) duration=5.000000
    sayLine 'Long minutes of furious berry picking later...'
    add breakwhilecond name=breakwhiletalking(all) pid=300115, Helpers.bnut (1103)
    add breakwhilecond name=breakwhilesound(-16408) pid=300110, playBearSounds ForestMaze.bnut (444)
    talking @25923: ended
    Resume task: 300115, Helpers.bnut (1103)
    cutsceneOverride
    create cutscene override
    saylineAt: (160,85) text= color=rgba(1.000000,0.800000,0.000000,1.000000) duration=0.000000
    scummvm: ./common/str-base.h:183: Common::BaseString<T>::value_type Common::BaseString<T>::operator[](int) const [with T = char; value_type = char]: Assertion `idx < (int)_size' failed.

The empty line comes from the fadeRoomMessage helper function
(Helpers.bnut:1115) and is meant to reset the talk state after the
cutscene is over, so the engine should be able to handle it without
crashing. Fix this by making SayLineAt::say() return early if called
with an empty script and adjust the cleanup code to handle the fact that
_node might not be initialized due to the early return.
This commit is contained in:
Apollon Oikonomopoulos 2024-07-22 14:48:20 +03:00 committed by scemino
parent 42df06e4f8
commit 1317afc79e

View File

@ -566,6 +566,11 @@ SayLineAt::SayLineAt(const Math::Vector2d &pos, const Color &color, Common::Shar
void SayLineAt::say(const Common::String &text) { void SayLineAt::say(const Common::String &text) {
Common::String txt(text); Common::String txt(text);
if (txt.size() == 0) {
debugC(kDebugGame, "say: skipping empty line");
return;
}
if (txt[0] == '$') { if (txt[0] == '$') {
HSQUIRRELVM v = g_twp->getVm(); HSQUIRRELVM v = g_twp->getVm();
SQInteger top = sq_gettop(v); SQInteger top = sq_gettop(v);
@ -662,7 +667,8 @@ void SayLineAt::onUpdate(float elapsed) {
void SayLineAt::disable() { void SayLineAt::disable() {
Motor::disable(); Motor::disable();
_node->remove(); if (_node)
_node->remove();
} }
Jiggle::Jiggle(Node *node, float amount) : _amount(amount), _node(node) { Jiggle::Jiggle(Node *node, float amount) : _amount(amount), _node(node) {