Skip to content

Commit

Permalink
DIRECTOR: Lingo: Nicer error recovery during execution
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Aug 3, 2016
1 parent ffdb3f9 commit 4d2e4a8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 20 additions & 3 deletions engines/director/lingo/lingo-code.cpp
Expand Up @@ -608,14 +608,25 @@ void Lingo::c_call() {
Common::String name((char *)&(*g_lingo->_currentScript)[g_lingo->_pc]);
g_lingo->_pc += g_lingo->calcStringAlignment(name.c_str());

int nargs = READ_UINT32(&(*g_lingo->_currentScript)[g_lingo->_pc++]);

if (!g_lingo->_handlers.contains(name)) {
error("Call to undefined handler '%s'", name.c_str());
warning("Call to undefined handler '%s'. Dropping %d stack items", name.c_str(), nargs);

for (int i = 0; i < nargs; i++)
g_lingo->pop();

// Push dummy value
Datum d;
d.u.i = 0;
d.type = VOID;
g_lingo->push(d);

return;
}

Symbol *sym = g_lingo->_handlers[name];

int nargs = READ_UINT32(&(*g_lingo->_currentScript)[g_lingo->_pc++]);

for (int i = nargs; i < sym->nargs; i++) {
Datum d;

Expand Down Expand Up @@ -643,6 +654,12 @@ void Lingo::c_call() {
}

void Lingo::c_procret() {
if (!g_lingo->_callstack.size()) {
warning("Call stack underflow");
g_lingo->_returning = true;
return;
}

CFrame *fp = g_lingo->_callstack.back();

g_lingo->_currentScript = fp->retscript;
Expand Down
2 changes: 1 addition & 1 deletion engines/director/lingo/lingo-funcs.cpp
Expand Up @@ -190,7 +190,7 @@ void Lingo::func_mciwait(Common::String &s) {
}

void Lingo::func_goto(Common::String &frame, Common::String &movie) {
if (!_vm->_movies->contains(movie))
if (!_vm->_movies || !_vm->_movies->contains(movie))
error("Movie %s does not exist", movie.c_str());

_vm->_currentScore = _vm->_movies->getVal(movie);
Expand Down

0 comments on commit 4d2e4a8

Please sign in to comment.