Crash-fix: mat-lib is now reference-counted.
Adapt to corresponding SG change to make SGMaterialLib be ref-counted, and have the 'reload-materials' command notify the tile-manager of this, so it can update the options struct it passes to new tiles.
This commit is contained in:
parent
2df74c9b63
commit
ce3a7b20fe
7 changed files with 35 additions and 24 deletions
|
@ -31,6 +31,7 @@
|
|||
#include <GUI/dialog.hxx>
|
||||
#include <Aircraft/replay.hxx>
|
||||
#include <Scenery/scenery.hxx>
|
||||
#include <Scenery/tilemgr.hxx>
|
||||
#include <Scripting/NasalSys.hxx>
|
||||
#include <Sound/sample_queue.hxx>
|
||||
#include <Airports/xmlloader.hxx>
|
||||
|
@ -500,26 +501,29 @@ do_tile_cache_reload (const SGPropertyNode * arg)
|
|||
/**
|
||||
* Reload the materials definition
|
||||
*/
|
||||
static bool
|
||||
do_materials_reload (const SGPropertyNode * arg)
|
||||
{
|
||||
SG_LOG(SG_INPUT, SG_INFO, "Reloading Materials");
|
||||
SGMaterialLib* new_matlib = new SGMaterialLib;
|
||||
SGPath mpath( globals->get_fg_root() );
|
||||
mpath.append( fgGetString("/sim/rendering/materials-file") );
|
||||
bool loaded = new_matlib->load(globals->get_fg_root(),
|
||||
static bool
|
||||
do_materials_reload (const SGPropertyNode * arg)
|
||||
{
|
||||
SG_LOG(SG_INPUT, SG_INFO, "Reloading Materials");
|
||||
SGMaterialLib* new_matlib = new SGMaterialLib;
|
||||
SGPath mpath( globals->get_fg_root() );
|
||||
mpath.append( fgGetString("/sim/rendering/materials-file") );
|
||||
bool loaded = new_matlib->load(globals->get_fg_root(),
|
||||
mpath.str(),
|
||||
globals->get_props());
|
||||
|
||||
if ( ! loaded ) {
|
||||
|
||||
if ( ! loaded ) {
|
||||
SG_LOG( SG_GENERAL, SG_ALERT,
|
||||
"Error loading materials file " << mpath.str() );
|
||||
return false;
|
||||
}
|
||||
|
||||
globals->set_matlib(new_matlib);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
globals->set_matlib(new_matlib);
|
||||
FGTileMgr* tileManager = static_cast<FGTileMgr*>(globals->get_subsystem("tile-manager"));
|
||||
tileManager->materialLibChanged();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
|
|
|
@ -145,7 +145,6 @@ FGGlobals::FGGlobals() :
|
|||
fg_home( "" ),
|
||||
time_params( NULL ),
|
||||
ephem( NULL ),
|
||||
matlib( NULL ),
|
||||
route_mgr( NULL ),
|
||||
ATIS_mgr( NULL ),
|
||||
controls( NULL ),
|
||||
|
@ -764,8 +763,6 @@ void FGGlobals::set_tile_mgr ( FGTileMgr *t )
|
|||
|
||||
void FGGlobals::set_matlib( SGMaterialLib *m )
|
||||
{
|
||||
if (matlib)
|
||||
delete matlib;
|
||||
matlib = m;
|
||||
}
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ private:
|
|||
SGEphemeris *ephem;
|
||||
|
||||
// Material properties library
|
||||
SGMaterialLib *matlib;
|
||||
SGSharedPtr<SGMaterialLib> matlib;
|
||||
|
||||
// Global autopilot "route"
|
||||
FGRouteMgr *route_mgr;
|
||||
|
|
|
@ -86,7 +86,8 @@ void FGTileMgr::init() {
|
|||
SG_LOG( SG_TERRAIN, SG_INFO, "Initializing Tile Manager subsystem." );
|
||||
|
||||
_options = new simgear::SGReaderWriterOptions;
|
||||
_options->setMaterialLib(globals->get_matlib());
|
||||
|
||||
materialLibChanged();
|
||||
_options->setPropertyNode(globals->get_props());
|
||||
|
||||
osgDB::FilePathList &fp = _options->getDatabasePathList();
|
||||
|
@ -116,8 +117,7 @@ void FGTileMgr::reinit()
|
|||
fgSetBool("/sim/sceneryloaded",false);
|
||||
fgSetDouble("/sim/startup/splash-alpha", 1.0);
|
||||
|
||||
// Reload the materials definitions
|
||||
_options->setMaterialLib(globals->get_matlib());
|
||||
materialLibChanged();
|
||||
|
||||
// remove all old scenery nodes from scenegraph and clear cache
|
||||
osg::Group* group = globals->get_scenery()->get_terrain_branch();
|
||||
|
@ -141,6 +141,12 @@ void FGTileMgr::reinit()
|
|||
update(0.0);
|
||||
}
|
||||
|
||||
void FGTileMgr::materialLibChanged()
|
||||
{
|
||||
_options->setMaterialLib(globals->get_matlib());
|
||||
_options->getMaterialLib()->refreshActiveMaterials();
|
||||
}
|
||||
|
||||
/* schedule a tile for loading, keep request for given amount of time.
|
||||
* Returns true if tile is already loaded. */
|
||||
bool FGTileMgr::sched_tile( const SGBucket& b, double priority, bool current_view, double duration)
|
||||
|
|
|
@ -110,6 +110,10 @@ public:
|
|||
|
||||
// Returns true if tiles around current view position have been loaded
|
||||
bool isSceneryLoaded();
|
||||
|
||||
// notify the tile manahger the material library was reloaded,
|
||||
// so it can pass this through to its options object
|
||||
void materialLibChanged();
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ main(int argc, char** argv)
|
|||
simgear::ModelRegistry::instance();
|
||||
|
||||
sgUserDataInit(props.get());
|
||||
SGMaterialLib* ml = new SGMaterialLib;
|
||||
SGMaterialLibPtr ml = new SGMaterialLib;
|
||||
SGPath mpath(fg_root);
|
||||
mpath.append("Materials/default/materials.xml");
|
||||
try {
|
||||
|
|
|
@ -179,7 +179,7 @@ main(int argc, char** argv)
|
|||
// FIXME Ok, replace this by querying the root of the property tree
|
||||
sgUserDataInit(props.get());
|
||||
SGSceneFeatures::instance()->setTextureCompression(SGSceneFeatures::DoNotUseCompression);
|
||||
SGMaterialLib* ml = new SGMaterialLib;
|
||||
SGMaterialLibPtr ml = new SGMaterialLib;
|
||||
SGPath mpath(fg_root);
|
||||
mpath.append("Materials/default/materials.xml");
|
||||
try {
|
||||
|
|
Loading…
Add table
Reference in a new issue