From b588a92b7f31cc7030077c1906c9014d7e7bb437 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Tue, 16 Jun 2009 10:41:17 +0200 Subject: [PATCH] adapt to changes in sg_exception interface sg_location now uses C strings. Also, change uses of sg_throwable to more specific exceptions like sg_io_exception. --- src/Cockpit/hud.cxx | 6 ++++-- src/FDM/YASim/proptest.cpp | 2 +- src/FDM/YASim/yasim-test.cpp | 2 +- src/GUI/gui_funcs.cxx | 2 +- src/Input/input.cxx | 4 ++-- src/Instrumentation/HUD/HUD.cxx | 10 +++++++--- src/Instrumentation/instrument_mgr.cxx | 6 +++--- src/Main/bootstrap.cxx | 2 +- src/Main/fg_init.cxx | 2 +- 9 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/Cockpit/hud.cxx b/src/Cockpit/hud.cxx index e6903caab..f9b9f3a97 100644 --- a/src/Cockpit/hud.cxx +++ b/src/Cockpit/hud.cxx @@ -261,9 +261,11 @@ int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ ) } FGFontCache *fc = globals->get_fontcache(); - HUD_Font = fc->getTexFont(fgGetString("/sim/hud/font/name", "Helvetica.txf")); + const char* fileName = fgGetString("/sim/hud/font/name", "Helvetica.txf"); + HUD_Font = fc->getTexFont(fileName); if (!HUD_Font) - throw sg_throwable(string("/sim/hud/font/name is not a texture font")); + throw sg_io_exception("/sim/hud/font/name is not a texture font", + sg_location(fileName)); HUD_TextSize = fgGetFloat("/sim/hud/font/size", 10); diff --git a/src/FDM/YASim/proptest.cpp b/src/FDM/YASim/proptest.cpp index 6db6183f7..c10d59211 100644 --- a/src/FDM/YASim/proptest.cpp +++ b/src/FDM/YASim/proptest.cpp @@ -51,7 +51,7 @@ int main(int argc, char** argv) readXML(argv[1], fdm); } catch (const sg_exception &e) { printf("XML parse error: %s (%s)\n", - e.getFormattedMessage().c_str(), e.getOrigin().c_str()); + e.getFormattedMessage().c_str(), e.getOrigin()); } Airplane* airplane = fdm.getAirplane(); diff --git a/src/FDM/YASim/yasim-test.cpp b/src/FDM/YASim/yasim-test.cpp index 2fa642526..095887341 100644 --- a/src/FDM/YASim/yasim-test.cpp +++ b/src/FDM/YASim/yasim-test.cpp @@ -85,7 +85,7 @@ int main(int argc, char** argv) readXML(file, *fdm); } catch (const sg_exception &e) { printf("XML parse error: %s (%s)\n", - e.getFormattedMessage().c_str(), e.getOrigin().c_str()); + e.getFormattedMessage().c_str(), e.getOrigin()); } // ... and run diff --git a/src/GUI/gui_funcs.cxx b/src/GUI/gui_funcs.cxx index 1dc5db7a4..1d2ccfba8 100644 --- a/src/GUI/gui_funcs.cxx +++ b/src/GUI/gui_funcs.cxx @@ -141,7 +141,7 @@ void guiErrorMessage (const char *txt, const sg_throwable &throwable) string msg = txt; msg += '\n'; msg += throwable.getFormattedMessage(); - if (!throwable.getOrigin().empty()) { + if (!std::strlen(throwable.getOrigin()) != 0) { msg += "\n (reported by "; msg += throwable.getOrigin(); msg += ')'; diff --git a/src/Input/input.cxx b/src/Input/input.cxx index 695a42610..d281c3593 100644 --- a/src/Input/input.cxx +++ b/src/Input/input.cxx @@ -512,8 +512,8 @@ FGInput::_init_joystick () << "\"\nUsing default: \"" << source << '"'); } else { - throw sg_throwable(string("No joystick configuration file with " - "default entry found!")); + throw sg_exception(string("No joystick configuration file with ") + + name + " entry found!"); } js_node = js_nodes->getChild("js", i, true); diff --git a/src/Instrumentation/HUD/HUD.cxx b/src/Instrumentation/HUD/HUD.cxx index d199c3b30..65543dea3 100644 --- a/src/Instrumentation/HUD/HUD.cxx +++ b/src/Instrumentation/HUD/HUD.cxx @@ -127,11 +127,15 @@ HUD::~HUD() void HUD::init() { + const char* fontName = 0; _font_cache = globals->get_fontcache(); + if (!_font) { + fontName = fgGetString("/sim/hud/font/name", "Helvetica.txf"); + _font = _font_cache->getTexFont(fontName); + } if (!_font) - _font = _font_cache->getTexFont(fgGetString("/sim/hud/font/name", "Helvetica.txf")); - if (!_font) - throw sg_throwable(string("/sim/hud/font/name is not a texture font")); + throw sg_io_exception("/sim/hud/font/name is not a texture font", + sg_location(fontName)); _font_size = fgGetFloat("/sim/hud/font/size", 8); _font_renderer->setFont(_font); diff --git a/src/Instrumentation/instrument_mgr.cxx b/src/Instrumentation/instrument_mgr.cxx index da82cce95..21b2a47e7 100644 --- a/src/Instrumentation/instrument_mgr.cxx +++ b/src/Instrumentation/instrument_mgr.cxx @@ -70,9 +70,9 @@ FGInstrumentMgr::FGInstrumentMgr () readProperties( config.str(), config_props ); if ( !build() ) { - throw sg_throwable(string( - "Detected an internal inconsistency in the instrumentation\n" - "system specification file. See earlier errors for details.")); + throw sg_error( + "Detected an internal inconsistency in the instrumentation\n" + "system specification file. See earlier errors for details."); } } catch (const sg_exception&) { SG_LOG( SG_ALL, SG_ALERT, "Failed to load instrumentation system model: " diff --git a/src/Main/bootstrap.cxx b/src/Main/bootstrap.cxx index aa9c314a2..dc0723f37 100644 --- a/src/Main/bootstrap.cxx +++ b/src/Main/bootstrap.cxx @@ -219,7 +219,7 @@ int main ( int argc, char **argv ) { // logging, since logging may be // disabled. cerr << "Fatal error: " << t.getFormattedMessage() << endl; - if (!t.getOrigin().empty()) + if (std::strlen(t.getOrigin()) != 0) cerr << " (received from " << t.getOrigin() << ')' << endl; } catch (const string &s) { diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index b602efdf3..7079f3d20 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -1279,7 +1279,7 @@ void fgInitFDM() { } else if ( model == "yasim" ) { cur_fdm_state = new YASim( dt ); } else { - throw sg_throwable(string("Unrecognized flight model '") + model + throw sg_exception(string("Unrecognized flight model '") + model + "', cannot init flight dynamics model."); } }