From b338698c79f227a76994608b9bc6e54bedbfaaf2 Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 11 Jul 2001 18:54:50 +0000 Subject: [PATCH] - move data structure allocation into constructor (it doesn't belong in init) - free data structures in destructor - ensure that interpolation tables are allocated before any searching is done; otherwise, starting at some locations (such as CYYZ) causes a segfault --- src/Cockpit/radiostack.cxx | 46 +++++++++++++++++++++----------------- src/Cockpit/radiostack.hxx | 2 +- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/Cockpit/radiostack.cxx b/src/Cockpit/radiostack.cxx index bc41bbb9c..86057264d 100644 --- a/src/Cockpit/radiostack.cxx +++ b/src/Cockpit/radiostack.cxx @@ -78,15 +78,27 @@ static void fgRadioSearch( void ) { } // Constructor -FGRadioStack::FGRadioStack() { - nav1_radial = 0.0; - nav1_dme_dist = 0.0; - nav2_radial = 0.0; - nav2_dme_dist = 0.0; - need_update = true; - lon_node = fgGetNode("/position/longitude-deg"); - lat_node = fgGetNode("/position/latitude-deg"); - alt_node = fgGetNode("/position/altitude-ft"); +FGRadioStack::FGRadioStack() : + lon_node(fgGetNode("/position/longitude-deg", true)), + lat_node(fgGetNode("/position/latitude-deg", true)), + alt_node(fgGetNode("/position/altitude-ft", true)), + need_update(true), + nav1_radial(0.0), + nav1_dme_dist(0.0), + nav2_radial(0.0), + nav2_dme_dist(0.0) +{ + SGPath path( globals->get_fg_root() ); + SGPath term = path; + term.append( "Navaids/range.term" ); + SGPath low = path; + low.append( "Navaids/range.low" ); + SGPath high = path; + high.append( "Navaids/range.high" ); + + term_tbl = new SGInterpTable( term.str() ); + low_tbl = new SGInterpTable( low.str() ); + high_tbl = new SGInterpTable( high.str() ); } @@ -94,6 +106,10 @@ FGRadioStack::FGRadioStack() { FGRadioStack::~FGRadioStack() { unbind(); // FIXME: should be called externally + + delete term_tbl; + delete low_tbl; + delete high_tbl; } @@ -107,18 +123,6 @@ FGRadioStack::init () search(); update(); - SGPath path( globals->get_fg_root() ); - SGPath term = path; - term.append( "Navaids/range.term" ); - SGPath low = path; - low.append( "Navaids/range.low" ); - SGPath high = path; - high.append( "Navaids/range.high" ); - - term_tbl = new SGInterpTable( term.str() ); - low_tbl = new SGInterpTable( low.str() ); - high_tbl = new SGInterpTable( high.str() ); - // Search radio database once per second global_events.Register( "fgRadioSearch()", fgRadioSearch, fgEVENT::FG_EVENT_READY, 1000); diff --git a/src/Cockpit/radiostack.hxx b/src/Cockpit/radiostack.hxx index cf8873523..764b4bf5e 100644 --- a/src/Cockpit/radiostack.hxx +++ b/src/Cockpit/radiostack.hxx @@ -48,8 +48,8 @@ class FGRadioStack : public FGSubsystem SGInterpTable *low_tbl; SGInterpTable *high_tbl; - SGPropertyNode *lat_node; SGPropertyNode *lon_node; + SGPropertyNode *lat_node; SGPropertyNode *alt_node; bool need_update;