Use owning refs in some places

Avoid explicit deletes of ref-counted SGMaterialCache
This commit is contained in:
James Turner 2021-07-29 17:51:35 +01:00
parent fb436be8f1
commit d01e9ca2e6
4 changed files with 6 additions and 8 deletions

View File

@ -355,9 +355,8 @@ ref_ptr<Node> instantiateMaterialEffects(osg::Node* modelGroup,
if (options->getMaterialLib()) { if (options->getMaterialLib()) {
const SGGeod loc = SGGeod(options->getLocation()); const SGGeod loc = SGGeod(options->getLocation());
SGMaterialCache* matcache = options->getMaterialLib()->generateMatCache(loc, options); osg::ref_ptr<SGMaterialCache> matcache = options->getMaterialLib()->generateMatCache(loc, options);
SGMaterial* mat = matcache->find(options->getMaterialName()); SGMaterial* mat = matcache->find(options->getMaterialName());
delete matcache;
if (mat) { if (mat) {
effect = new SGPropertyNode(); effect = new SGPropertyNode();

View File

@ -280,9 +280,8 @@ osg::Node* SGOceanTile(const SGBucket& b, SGMaterialLib *matlib, int latPoints,
double tex_width = 1000.0; double tex_width = 1000.0;
// find Ocean material in the properties list // find Ocean material in the properties list
SGMaterialCache* matcache = matlib->generateMatCache(b.get_center(), 0); osg::ref_ptr<SGMaterialCache> matcache = matlib->generateMatCache(b.get_center(), 0);
SGMaterial* mat = matcache->find( "Ocean" ); SGMaterial* mat = matcache->find( "Ocean" );
delete matcache;
if ( mat != NULL ) { if ( mat != NULL ) {
// set the texture width and height values for this // set the texture width and height values for this

View File

@ -274,13 +274,13 @@ public:
return true; return true;
} }
osg::Node* getSurfaceGeometry(SGMaterialCache* matcache, bool useVBOs) const osg::ref_ptr<osg::Node> getSurfaceGeometry(SGMaterialCache* matcache, bool useVBOs) const
{ {
if (materialTriangleMap.empty()) if (materialTriangleMap.empty())
return 0; return 0;
EffectGeode* eg = NULL; osg::ref_ptr<EffectGeode> eg = NULL;
osg::Group* group = (materialTriangleMap.size() > 1 ? new osg::Group : NULL); osg::ref_ptr<osg::Group> group = (materialTriangleMap.size() > 1 ? new osg::Group : NULL);
if (group) { if (group) {
group->setName("surfaceGeometryGroup"); group->setName("surfaceGeometryGroup");
} }

View File

@ -120,7 +120,7 @@ SGLoadBTG(const std::string& path, const simgear::SGReaderWriterOptions* options
if (!tileGeometryBin->insertSurfaceGeometry(tile, matcache)) if (!tileGeometryBin->insertSurfaceGeometry(tile, matcache))
return NULL; return NULL;
osg::Node* node = tileGeometryBin->getSurfaceGeometry(matcache, useVBOs); osg::ref_ptr<osg::Node> node = tileGeometryBin->getSurfaceGeometry(matcache, useVBOs);
if (node) { if (node) {
// Get base node stateset // Get base node stateset