From 23c5be6fbe407e1a2380943e5a3084192fd876a2 Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Tue, 10 Sep 2013 04:21:41 +0200 Subject: [PATCH] Catch errors that could happen when reading Scripts.rxdata --- binding-mruby/binding-mruby.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/binding-mruby/binding-mruby.cpp b/binding-mruby/binding-mruby.cpp index e82d485..8f5d516 100644 --- a/binding-mruby/binding-mruby.cpp +++ b/binding-mruby/binding-mruby.cpp @@ -43,6 +43,7 @@ #include "texpool.h" #include "eventthread.h" #include "filesystem.h" +#include "exception.h" #include "binding-types.h" #include "mrb-ext/marshal.h" @@ -263,12 +264,25 @@ runRMXPScripts(mrb_state *mrb, mrbc_context *ctx) gState->fileSystem().openRead(ops, scriptPack.constData()); - mrb_value scriptArray = marshalLoadInt(scriptMrb, &ops); + mrb_value scriptArray = mrb_nil_value(); + QByteArray readError; + + try + { + scriptArray = marshalLoadInt(scriptMrb, &ops); + } + catch (const Exception &e) + { + char buffer[512]; + snprintf(buffer, sizeof(buffer), e.fmt.constData(), e.arg1.constData(), e.arg2.constData()); + readError = QByteArray(": ") + QByteArray(buffer); + } + SDL_RWclose(&ops); if (!mrb_array_p(scriptArray)) { - showError("Failed to read script data"); + showError(QByteArray("Failed to read script data") + readError); mrb_close(scriptMrb); return; }