From a686c61f1d9f2838f1f0b4eb97417797040d4dc2 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Mon, 22 Mar 2021 08:32:53 -0400 Subject: [PATCH] Use std::runtime_error to fix exception conversions. --- Engine.cpp | 13 +++++++++---- UserInterface.cpp | 36 +++++++++++++++++++++++++----------- b3view.depend | 8 ++++---- readme.md | 14 ++++++++++++++ settings.cpp | 2 +- 5 files changed, 53 insertions(+), 20 deletions(-) diff --git a/Engine.cpp b/Engine.cpp index eb09fc7..3c70dc2 100644 --- a/Engine.cpp +++ b/Engine.cpp @@ -72,10 +72,15 @@ void Engine::setEnableTextureInterpolation(bool EnableTextureInterpolation) void Engine::addRecent(std::string path) { - if (!this->hasRecent(path)) { - int count = this->countRecent(); - std::string name = "recent" + std::to_string(count); - this->settings.set(name, path); + try { + if (!this->hasRecent(path)) { + int count = this->countRecent(); + std::string name = "recent" + std::to_string(count); + this->settings.set(name, path); + } + } + catch (const std::runtime_error& ex) { + std::cerr << ex.what(); } } diff --git a/UserInterface.cpp b/UserInterface.cpp index 5fa5da3..cea92ab 100644 --- a/UserInterface.cpp +++ b/UserInterface.cpp @@ -794,15 +794,15 @@ void UserInterface::clearRecent() void UserInterface::addRecentMenuItem(std::string path, bool addToEngine) { if (!this->recent_initialized) { - throw std::string("The UI is not ready in addRecent."); + throw std::runtime_error("The UI is not ready in addRecent."); } if (!this->hasRecent(path)) { wstring path_ws = Utility::toWstring(path); if (this->uic_file_recent_next < UserInterface::UIC_FILE_RECENT_FIRST) { - throw std::string("this->uic_file_recent_next is " - + std::to_string(this->uic_file_recent_next) - + " but should be equal to or greater than first: " - + std::to_string(this->uic_file_recent_next)); + throw std::runtime_error("this->uic_file_recent_next is " + + std::to_string(this->uic_file_recent_next) + + " but should be equal to or greater than first: " + + std::to_string(this->uic_file_recent_next)); } u32 newI = this->recentMenu->addItem(path_ws.c_str(), this->uic_file_recent_next); // IGUIContextMenu* menu = this->recentMenu->getSubMenu(newI); @@ -821,17 +821,23 @@ void UserInterface::addRecentMenuItem(std::string path, bool addToEngine) void UserInterface::addRecentMenuItems(std::vector paths, bool addToEngine) { if (!this->recent_initialized) { - throw std::string("The UI is not ready in addRecent."); + throw std::runtime_error("The UI is not ready in addRecent."); } for (std::vector::iterator it = paths.begin() ; it != paths.end(); ++it) { - this->addRecentMenuItem(*it, addToEngine); + try { + this->addRecentMenuItem(*it, addToEngine); + } + catch (const std::runtime_error& ex) { + cerr << ex.what(); + break; + } } } bool UserInterface::hasRecent(std::string path) { if (!this->recent_initialized) { - throw std::string("The UI is not ready in addRecent."); + throw std::runtime_error("The UI is not ready in addRecent."); } for (std::vector::iterator uiIt = this->recentIndices.begin() ; uiIt != this->recentIndices.end(); ++uiIt) { IGUIContextMenu* menu = this->recentMenu->getSubMenu(*uiIt); @@ -843,7 +849,7 @@ bool UserInterface::hasRecent(std::string path) else { const std::string msg = "There was no menu for " + std::to_string(*uiIt) + " in hasRecent"; cerr << msg << endl; - throw std::string(msg); + throw std::runtime_error(msg); } } return false; @@ -852,7 +858,7 @@ bool UserInterface::hasRecent(std::string path) void UserInterface::openRecent(s32 menuID, std::wstring menuText) { if (!this->recent_initialized) { - throw std::string("The UI is not ready in addRecent."); + throw std::runtime_error("The UI is not ready in addRecent."); } IGUIElement* menu = this->recentMenu->getElementFromId(menuID); std::string path = Utility::toString(menu->getText()); @@ -899,8 +905,16 @@ bool UserInterface::OnEvent(const SEvent& event) else { result = m_Engine->loadMesh(fileOpenDialog->getFileName()); } - this->addRecentMenuItem(Utility::toString(path), true); + if (result) { + try { + this->addRecentMenuItem(Utility::toString(path), true); + } + catch (const std::runtime_error& ex) { + cerr << ex.what(); + break; + } + } if (!result) { this->m_Engine->m_Device->getGUIEnvironment()->addMessageBox( L"Load Mesh", L"The model is inaccessible or not in a compatible format."); diff --git a/b3view.depend b/b3view.depend index 679715b..3cfe31d 100644 --- a/b3view.depend +++ b/b3view.depend @@ -2,10 +2,10 @@ 1554970747 source:/opt/b3view/Debug.cpp "Debug.h" -1554970753 /opt/b3view/Debug.h +1616415754 /opt/b3view/Debug.h -1613679774 source:/opt/b3view/Engine.cpp +1616415912 source:/opt/b3view/Engine.cpp "Engine.h" @@ -76,7 +76,7 @@ "Engine.h" -1613683794 source:/opt/b3view/settings.cpp +1616415840 source:/opt/b3view/settings.cpp "Utility.h" "settings.h" @@ -85,7 +85,7 @@ -1613683794 source:/opt/b3view/UserInterface.cpp +1616415979 source:/opt/b3view/UserInterface.cpp "Debug.h" "Engine.h" "Utility.h" diff --git a/readme.md b/readme.md index aaa0edd..84b439c 100644 --- a/readme.md +++ b/readme.md @@ -11,6 +11,20 @@ Website: [poikilos.org](https://poikilos.org) ## Requirements * libirrlicht + (or libirrlicht1.8) + +### Development + +* libirrlicht-dbg + (or libirrlicht1.8-dbg) +* libfreetype6-dev + - In CodeBlocks (once per computer): Settings, Compiler, Search paths, /usr/include/freetype2 + - Ensure includes do not put freetype2 first (that directory contains freetype and ft2build.h. Also, freetype itself does its includes as freetype not freetype2/freetype). + +CodeBlocks says it is looking for boost_filesystem and boost_system, which may be due to Irrlicht. +* libbost-filesystem-dev + - In CodeBlocks (once per computer): Settings, Compiler, Search paths, /usr/include/freetype2 +* libboost-system-dev ## Main Features in poikilos fork * stabilized (makes sure font, model or texture loads before using; diff --git a/settings.cpp b/settings.cpp index 9715fa6..b5f8614 100644 --- a/settings.cpp +++ b/settings.cpp @@ -194,7 +194,7 @@ bool Settings::save(std::string path) bool Settings::save() { if (this->path.length() == 0) { - throw std::string("There is no path during save()."); + throw std::runtime_error("There is no path during save()."); } return this->save(this->path); }