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:
James Turner 2014-01-19 16:45:01 +00:00
parent 12d0d4140e
commit 3b5ed81216
3 changed files with 12 additions and 7 deletions

View File

@ -27,6 +27,7 @@
#include <simgear/compiler.h>
#include <simgear/structure/SGReferenced.hxx>
#include <simgear/structure/SGSharedPtr.hxx>
#include <memory>
@ -41,7 +42,8 @@ namespace simgear { class Effect; }
namespace osg { class Geode; }
// Material management class
class SGMaterialLib {
class SGMaterialLib : public SGReferenced
{
private:
class MatLibPrivate;
@ -99,5 +101,6 @@ public:
~SGMaterialLib ( void );
};
typedef SGSharedPtr<SGMaterialLib> SGMaterialLibPtr;
#endif // _MATLIB_HXX

View File

@ -905,7 +905,7 @@ public:
// Generate all the lighting objects for the tile.
osg::LOD* generateLightingTileObjects()
{
SGMaterialLib* matlib = NULL;
SGMaterialLibPtr matlib;
if (_options)
matlib = _options->getMaterialLib();
@ -1046,7 +1046,7 @@ public:
// Generate all the random forest, objects and buildings for the tile
osg::LOD* generateRandomTileObjects()
{
SGMaterialLib* matlib = NULL;
SGMaterialLibPtr matlib;
bool use_random_objects = false;
bool use_random_vegetation = false;
bool use_random_buildings = false;
@ -1181,7 +1181,7 @@ SGLoadBTG(const std::string& path, const simgear::SGReaderWriterOptions* options
if (!tile.read_bin(path))
return NULL;
SGMaterialLib* matlib = 0;
SGMaterialLibPtr matlib;
if (options) {
matlib = options->getMaterialLib();

View File

@ -22,10 +22,12 @@
#include <osgDB/Options>
#include <simgear/scene/model/modellib.hxx>
#include <simgear/scene/material/matlib.hxx>
#include <simgear/props/props.hxx>
class SGPropertyNode;
class SGMaterialLib;
namespace simgear
{
@ -70,7 +72,7 @@ public:
void setPropertyNode(const SGSharedPtr<SGPropertyNode>& propertyNode)
{ _propertyNode = propertyNode; }
SGMaterialLib* getMaterialLib() const
SGMaterialLibPtr getMaterialLib() const
{ return _materialLib; }
void setMaterialLib(SGMaterialLib* materialLib)
{ _materialLib = materialLib; }
@ -100,7 +102,7 @@ protected:
private:
SGSharedPtr<SGPropertyNode> _propertyNode;
SGMaterialLib* _materialLib;
SGSharedPtr<SGMaterialLib> _materialLib;
osg::Node *(*_load_panel)(SGPropertyNode *);
osg::ref_ptr<SGModelData> _model_data;
bool _instantiateEffects;