Crash-fix: make mat-lib reference counted.
Make SGReaderWriterOptions own the material lib it's passing to loader code, so it cannot be freed unexpectedly.
This commit is contained in:
parent
12d0d4140e
commit
3b5ed81216
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
|
|
||||||
|
#include <simgear/structure/SGReferenced.hxx>
|
||||||
#include <simgear/structure/SGSharedPtr.hxx>
|
#include <simgear/structure/SGSharedPtr.hxx>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -41,7 +42,8 @@ namespace simgear { class Effect; }
|
|||||||
namespace osg { class Geode; }
|
namespace osg { class Geode; }
|
||||||
|
|
||||||
// Material management class
|
// Material management class
|
||||||
class SGMaterialLib {
|
class SGMaterialLib : public SGReferenced
|
||||||
|
{
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class MatLibPrivate;
|
class MatLibPrivate;
|
||||||
@ -99,5 +101,6 @@ public:
|
|||||||
~SGMaterialLib ( void );
|
~SGMaterialLib ( void );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef SGSharedPtr<SGMaterialLib> SGMaterialLibPtr;
|
||||||
|
|
||||||
#endif // _MATLIB_HXX
|
#endif // _MATLIB_HXX
|
||||||
|
@ -905,7 +905,7 @@ public:
|
|||||||
// Generate all the lighting objects for the tile.
|
// Generate all the lighting objects for the tile.
|
||||||
osg::LOD* generateLightingTileObjects()
|
osg::LOD* generateLightingTileObjects()
|
||||||
{
|
{
|
||||||
SGMaterialLib* matlib = NULL;
|
SGMaterialLibPtr matlib;
|
||||||
|
|
||||||
if (_options)
|
if (_options)
|
||||||
matlib = _options->getMaterialLib();
|
matlib = _options->getMaterialLib();
|
||||||
@ -1046,7 +1046,7 @@ public:
|
|||||||
// Generate all the random forest, objects and buildings for the tile
|
// Generate all the random forest, objects and buildings for the tile
|
||||||
osg::LOD* generateRandomTileObjects()
|
osg::LOD* generateRandomTileObjects()
|
||||||
{
|
{
|
||||||
SGMaterialLib* matlib = NULL;
|
SGMaterialLibPtr matlib;
|
||||||
bool use_random_objects = false;
|
bool use_random_objects = false;
|
||||||
bool use_random_vegetation = false;
|
bool use_random_vegetation = false;
|
||||||
bool use_random_buildings = false;
|
bool use_random_buildings = false;
|
||||||
@ -1181,7 +1181,7 @@ SGLoadBTG(const std::string& path, const simgear::SGReaderWriterOptions* options
|
|||||||
if (!tile.read_bin(path))
|
if (!tile.read_bin(path))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
SGMaterialLib* matlib = 0;
|
SGMaterialLibPtr matlib;
|
||||||
|
|
||||||
if (options) {
|
if (options) {
|
||||||
matlib = options->getMaterialLib();
|
matlib = options->getMaterialLib();
|
||||||
|
@ -22,10 +22,12 @@
|
|||||||
|
|
||||||
#include <osgDB/Options>
|
#include <osgDB/Options>
|
||||||
#include <simgear/scene/model/modellib.hxx>
|
#include <simgear/scene/model/modellib.hxx>
|
||||||
|
#include <simgear/scene/material/matlib.hxx>
|
||||||
|
|
||||||
#include <simgear/props/props.hxx>
|
#include <simgear/props/props.hxx>
|
||||||
|
|
||||||
class SGPropertyNode;
|
class SGPropertyNode;
|
||||||
class SGMaterialLib;
|
|
||||||
|
|
||||||
namespace simgear
|
namespace simgear
|
||||||
{
|
{
|
||||||
@ -70,7 +72,7 @@ public:
|
|||||||
void setPropertyNode(const SGSharedPtr<SGPropertyNode>& propertyNode)
|
void setPropertyNode(const SGSharedPtr<SGPropertyNode>& propertyNode)
|
||||||
{ _propertyNode = propertyNode; }
|
{ _propertyNode = propertyNode; }
|
||||||
|
|
||||||
SGMaterialLib* getMaterialLib() const
|
SGMaterialLibPtr getMaterialLib() const
|
||||||
{ return _materialLib; }
|
{ return _materialLib; }
|
||||||
void setMaterialLib(SGMaterialLib* materialLib)
|
void setMaterialLib(SGMaterialLib* materialLib)
|
||||||
{ _materialLib = materialLib; }
|
{ _materialLib = materialLib; }
|
||||||
@ -100,7 +102,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
SGSharedPtr<SGPropertyNode> _propertyNode;
|
SGSharedPtr<SGPropertyNode> _propertyNode;
|
||||||
SGMaterialLib* _materialLib;
|
SGSharedPtr<SGMaterialLib> _materialLib;
|
||||||
osg::Node *(*_load_panel)(SGPropertyNode *);
|
osg::Node *(*_load_panel)(SGPropertyNode *);
|
||||||
osg::ref_ptr<SGModelData> _model_data;
|
osg::ref_ptr<SGModelData> _model_data;
|
||||||
bool _instantiateEffects;
|
bool _instantiateEffects;
|
||||||
|
Loading…
Reference in New Issue
Block a user