TOLTECS: Work around undefined subtitle behaviour at script loading

It may be because of an underlying bug, but there is at least one
case where a script is unloaded and replaced by another script while
that script slot still has an active subtitle. This causes it to
print random garbage for me, and may be causing crashes for others.

I've discussed this patch with johndoe, and he was ok with it, so
let's see how it works out.
This commit is contained in:
Torbjörn Andersson 2013-03-15 18:48:44 +01:00
parent 5dae972237
commit 4b0d0ecdda
3 changed files with 21 additions and 0 deletions

View file

@ -170,6 +170,18 @@ void ScriptInterpreter::setupScriptFunctions() {
}
void ScriptInterpreter::loadScript(uint resIndex, uint slotIndex) {
if (_slots[slotIndex].resIndex && _slots[slotIndex].resIndex != resIndex && _vm->_screen->isTalkTextActive(slotIndex)) {
// WORKAROUND: This happens when examining the assembled
// pickaxe. It could lead to random characters being printed,
// or possibly even crashes, when subtitles are enabled.
//
// According to johndoe and he said there may be some bug or
// missing feature that causes this situation to happen at all,
// but he was ok with this workaround for now.
warning("Possible script bug: Loading script %d into slot %d that has an active talk text, probably for script %d", resIndex, slotIndex, _slots[slotIndex].resIndex);
_vm->_screen->finishTalkTextItem(slotIndex);
}
delete[] _slots[slotIndex].data;
_slots[slotIndex].resIndex = resIndex;