Use std::runtime_error to fix exception conversions.

master
poikilos 2021-03-22 08:32:53 -04:00
parent 7761dea137
commit a686c61f1d
5 changed files with 53 additions and 20 deletions

View File

@ -72,10 +72,15 @@ void Engine::setEnableTextureInterpolation(bool EnableTextureInterpolation)
void Engine::addRecent(std::string path) void Engine::addRecent(std::string path)
{ {
if (!this->hasRecent(path)) { try {
int count = this->countRecent(); if (!this->hasRecent(path)) {
std::string name = "recent" + std::to_string(count); int count = this->countRecent();
this->settings.set(name, path); std::string name = "recent" + std::to_string(count);
this->settings.set(name, path);
}
}
catch (const std::runtime_error& ex) {
std::cerr << ex.what();
} }
} }

View File

@ -794,15 +794,15 @@ void UserInterface::clearRecent()
void UserInterface::addRecentMenuItem(std::string path, bool addToEngine) void UserInterface::addRecentMenuItem(std::string path, bool addToEngine)
{ {
if (!this->recent_initialized) { 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)) { if (!this->hasRecent(path)) {
wstring path_ws = Utility::toWstring(path); wstring path_ws = Utility::toWstring(path);
if (this->uic_file_recent_next < UserInterface::UIC_FILE_RECENT_FIRST) { if (this->uic_file_recent_next < UserInterface::UIC_FILE_RECENT_FIRST) {
throw std::string("this->uic_file_recent_next is " throw std::runtime_error("this->uic_file_recent_next is "
+ std::to_string(this->uic_file_recent_next) + std::to_string(this->uic_file_recent_next)
+ " but should be equal to or greater than first: " + " but should be equal to or greater than first: "
+ std::to_string(this->uic_file_recent_next)); + std::to_string(this->uic_file_recent_next));
} }
u32 newI = this->recentMenu->addItem(path_ws.c_str(), 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); // IGUIContextMenu* menu = this->recentMenu->getSubMenu(newI);
@ -821,17 +821,23 @@ void UserInterface::addRecentMenuItem(std::string path, bool addToEngine)
void UserInterface::addRecentMenuItems(std::vector<std::string> paths, bool addToEngine) void UserInterface::addRecentMenuItems(std::vector<std::string> paths, bool addToEngine)
{ {
if (!this->recent_initialized) { 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<std::string>::iterator it = paths.begin() ; it != paths.end(); ++it) { for (std::vector<std::string>::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) bool UserInterface::hasRecent(std::string path)
{ {
if (!this->recent_initialized) { 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<u32>::iterator uiIt = this->recentIndices.begin() ; uiIt != this->recentIndices.end(); ++uiIt) { for (std::vector<u32>::iterator uiIt = this->recentIndices.begin() ; uiIt != this->recentIndices.end(); ++uiIt) {
IGUIContextMenu* menu = this->recentMenu->getSubMenu(*uiIt); IGUIContextMenu* menu = this->recentMenu->getSubMenu(*uiIt);
@ -843,7 +849,7 @@ bool UserInterface::hasRecent(std::string path)
else { else {
const std::string msg = "There was no menu for " + std::to_string(*uiIt) + " in hasRecent"; const std::string msg = "There was no menu for " + std::to_string(*uiIt) + " in hasRecent";
cerr << msg << endl; cerr << msg << endl;
throw std::string(msg); throw std::runtime_error(msg);
} }
} }
return false; return false;
@ -852,7 +858,7 @@ bool UserInterface::hasRecent(std::string path)
void UserInterface::openRecent(s32 menuID, std::wstring menuText) void UserInterface::openRecent(s32 menuID, std::wstring menuText)
{ {
if (!this->recent_initialized) { 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); IGUIElement* menu = this->recentMenu->getElementFromId(menuID);
std::string path = Utility::toString(menu->getText()); std::string path = Utility::toString(menu->getText());
@ -899,8 +905,16 @@ bool UserInterface::OnEvent(const SEvent& event)
else { else {
result = m_Engine->loadMesh(fileOpenDialog->getFileName()); 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) { if (!result) {
this->m_Engine->m_Device->getGUIEnvironment()->addMessageBox( this->m_Engine->m_Device->getGUIEnvironment()->addMessageBox(
L"Load Mesh", L"The model is inaccessible or not in a compatible format."); L"Load Mesh", L"The model is inaccessible or not in a compatible format.");

View File

@ -2,10 +2,10 @@
1554970747 source:/opt/b3view/Debug.cpp 1554970747 source:/opt/b3view/Debug.cpp
"Debug.h" "Debug.h"
1554970753 /opt/b3view/Debug.h 1616415754 /opt/b3view/Debug.h
<iostream> <iostream>
1613679774 source:/opt/b3view/Engine.cpp 1616415912 source:/opt/b3view/Engine.cpp
<string> <string>
<filesystem> <filesystem>
"Engine.h" "Engine.h"
@ -76,7 +76,7 @@
"Engine.h" "Engine.h"
<Windows.h> <Windows.h>
1613683794 source:/opt/b3view/settings.cpp 1616415840 source:/opt/b3view/settings.cpp
"Utility.h" "Utility.h"
"settings.h" "settings.h"
<fstream> <fstream>
@ -85,7 +85,7 @@
<algorithm> <algorithm>
<assert.h> <assert.h>
1613683794 source:/opt/b3view/UserInterface.cpp 1616415979 source:/opt/b3view/UserInterface.cpp
"Debug.h" "Debug.h"
"Engine.h" "Engine.h"
"Utility.h" "Utility.h"

View File

@ -11,6 +11,20 @@ Website: [poikilos.org](https://poikilos.org)
## Requirements ## Requirements
* libirrlicht * 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 ## Main Features in poikilos fork
* stabilized (makes sure font, model or texture loads before using; * stabilized (makes sure font, model or texture loads before using;

View File

@ -194,7 +194,7 @@ bool Settings::save(std::string path)
bool Settings::save() bool Settings::save()
{ {
if (this->path.length() == 0) { 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); return this->save(this->path);
} }