From: Ingo Ruhnke Date: Tue, 26 Aug 2014 20:30:22 +0000 (+0200) Subject: A first try at error handling in the Downloader X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=84c71f11f1e47729777d6ad783f4d30b5894d7bc;p=supertux.git A first try at error handling in the Downloader This isn't fully working, as skipping the .then() callbacks skips over important cleanup and leads to failure further down the line. --- diff --git a/src/addon/downloader.cpp b/src/addon/downloader.cpp index 14d4dc4cb..fd8320b54 100644 --- a/src/addon/downloader.cpp +++ b/src/addon/downloader.cpp @@ -282,7 +282,6 @@ Downloader::update() TransferStatusPtr status = (*it)->get_status(); m_transfers.erase(it); - status->status = TransferStatus::COMPLETED; for(auto& callback : status->callbacks) { callback(); diff --git a/src/addon/downloader.hpp b/src/addon/downloader.hpp index 64d2384b6..de1155709 100644 --- a/src/addon/downloader.hpp +++ b/src/addon/downloader.hpp @@ -34,21 +34,20 @@ public: public: TransferId id; - Status status; + std::vector > callbacks; + int dltotal; int dlnow; int ultotal; int ulnow; - std::vector > callbacks; TransferStatus(TransferId id_) : id(id_), - status(RUNNING), + callbacks(), dltotal(0), dlnow(0), ultotal(0), - ulnow(0), - callbacks() + ulnow(0) {} void then(const std::function& callback) diff --git a/src/gui/menu_manager.cpp b/src/gui/menu_manager.cpp index a3c4b8e26..009a10a49 100644 --- a/src/gui/menu_manager.cpp +++ b/src/gui/menu_manager.cpp @@ -26,6 +26,7 @@ #include "supertux/globals.hpp" #include "supertux/menu/menu_storage.hpp" #include "supertux/timer.hpp" +#include "util/gettext.hpp" #include "util/log.hpp" #include "video/drawing_context.hpp" @@ -207,7 +208,17 @@ MenuManager::draw(DrawingContext& context) { if (m_dialog) { - m_dialog->update(); + try + { + m_dialog->update(); + } + catch(const std::exception& err) + { + m_dialog = std::unique_ptr(new Dialog); + m_dialog->set_text(_("Error:\n") + err.what()); + m_dialog->add_button(_("Ok")); + } + m_dialog->draw(context); } else if (current_menu())