From: ehofman Date: Tue, 24 Jan 2006 14:44:35 +0000 (+0000) Subject: Mathias Fröhlich: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c2c0e19305ea3bcf8da63a42a05a70d106c394ae;p=simgear.git Mathias Fröhlich: Incorporating the shared ptr code: - All scenegraph references from SimGear - SGMaterial which already had a reference counter uses now that common infrastructure. - SGMatModel is now counted. - SGSoundSample from SimGear - And the corresponding change for the sound samples in flightgear which fixes a latent crash if FGBeacon would evern be deleted. --- diff --git a/simgear/environment/visual_enviro.cxx b/simgear/environment/visual_enviro.cxx index 8daab27c..41df969b 100644 --- a/simgear/environment/visual_enviro.cxx +++ b/simgear/environment/visual_enviro.cxx @@ -26,6 +26,8 @@ #include #include +#include +#include #include #include #include @@ -655,7 +657,7 @@ void SGEnviro::drawLightning(void) { double ax = 0.0, ay = 0.0; ax = cos(course) * dist; ay = sin(course) * dist; - SGSoundSample *snd = soundMgr->find("thunder"); + SGSharedPtr snd = soundMgr->find("thunder"); if( snd ) { ALfloat pos[3]={ax, ay, -sgEnviro.last_alt }; snd->set_source_pos(pos); diff --git a/simgear/scene/material/mat.cxx b/simgear/scene/material/mat.cxx index 1c1258d9..ce5e78a9 100644 --- a/simgear/scene/material/mat.cxx +++ b/simgear/scene/material/mat.cxx @@ -74,10 +74,6 @@ SGMaterial::SGMaterial( ssgSimpleState *s ) SGMaterial::~SGMaterial (void) { - for (unsigned int i = 0; i < object_groups.size(); i++) { - delete object_groups[i]; - object_groups[i] = 0; - } } @@ -182,7 +178,6 @@ SGMaterial::init () wrapv = true; mipmap = true; light_coverage = 0.0; - refcount = 0; shininess = 1.0; for (int i = 0; i < 4; i++) { ambient[i] = (i < 3) ? 0.2 : 1.0; @@ -238,7 +233,6 @@ SGMaterial::build_ssg_state( bool defer_tex_load ) for (unsigned int i = 0; i < _status.size(); i++) { ssgSimpleState *state = new ssgSimpleState(); - state->ref(); // Set up the textured state state->setShadeModel( shade_model ); @@ -279,9 +273,7 @@ SGMaterial::build_ssg_state( bool defer_tex_load ) void SGMaterial::set_ssg_state( ssgSimpleState *s ) { - _internal_state st( s, "", true ); - st.state->ref(); - _status.push_back( st ); + _status.push_back( _internal_state( s, "", true ) ); } // end of mat.cxx diff --git a/simgear/scene/material/mat.hxx b/simgear/scene/material/mat.hxx index b980a006..106b0e39 100644 --- a/simgear/scene/material/mat.hxx +++ b/simgear/scene/material/mat.hxx @@ -39,6 +39,8 @@ #include #include +#include +#include #include "matmodel.hxx" @@ -55,7 +57,7 @@ SG_USING_STD(vector); * defined in the $FG_ROOT/materials.xml file, and can be changed * at runtime. */ -class SGMaterial { +class SGMaterial : public SGReferenced { public: @@ -161,29 +163,6 @@ public: return object_groups[index]; } - - /** - * Increment the reference count for this material. - * - * A material with 0 references may be deleted by the - * material library. - */ - virtual inline void ref () { refcount++; } - - - /** - * Decrement the reference count for this material. - */ - virtual inline void deRef () { refcount--; } - - - /** - * Get the reference count for this material. - * - * @return The number of references (0 if none). - */ - virtual inline int getRef () const { return refcount; } - protected: @@ -201,7 +180,7 @@ protected: struct _internal_state { _internal_state( ssgSimpleState *s, const string &t, bool l ) : state(s), texture_path(t), texture_loaded(l) {} - ssgSimpleState *state; + ssgSharedPtr state; string texture_path; bool texture_loaded; }; @@ -235,12 +214,7 @@ private: sgVec4 ambient, diffuse, specular, emission; double shininess; - vector object_groups; - - // ref count so we can properly delete if we have multiple - // pointers to this record - int refcount; - + vector > object_groups; //////////////////////////////////////////////////////////////////// diff --git a/simgear/scene/material/matlib.cxx b/simgear/scene/material/matlib.cxx index 7264022d..15406eaa 100644 --- a/simgear/scene/material/matlib.cxx +++ b/simgear/scene/material/matlib.cxx @@ -192,12 +192,11 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char for (int i = 0; i < nMaterials; i++) { const SGPropertyNode * node = materials.getChild(i); if (!strcmp(node->getName(), "material")) { - SGMaterial *m = new SGMaterial( fg_root, node, season ); + SGSharedPtr m = new SGMaterial( fg_root, node, season ); vectornames = node->getChildren("name"); for ( unsigned int j = 0; j < names.size(); j++ ) { string name = names[j]->getStringValue(); - m->ref(); // cerr << "Material " << name << endl; matlib[name] = m; SG_LOG( SG_TERRAIN, SG_INFO, " Loading material " @@ -211,7 +210,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char // hard coded ground light state ssgSimpleState *gnd_lights = new ssgSimpleState; - gnd_lights->ref(); gnd_lights->disable( GL_TEXTURE_2D ); gnd_lights->enable( GL_CULL_FACE ); gnd_lights->enable( GL_COLOR_MATERIAL ); @@ -228,7 +226,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char // hard coded runway white light state tex_name = gen_standard_dir_light_map( 235, 235, 195, 255 ); ssgSimpleState *rwy_white_lights = new ssgSimpleState(); - rwy_white_lights->ref(); rwy_white_lights->disable( GL_LIGHTING ); rwy_white_lights->enable ( GL_CULL_FACE ) ; rwy_white_lights->enable( GL_TEXTURE_2D ); @@ -249,7 +246,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char // hard coded runway medium intensity white light state tex_name = gen_standard_dir_light_map( 235, 235, 195, 205 ); ssgSimpleState *rwy_white_medium_lights = new ssgSimpleState(); - rwy_white_medium_lights->ref(); rwy_white_medium_lights->disable( GL_LIGHTING ); rwy_white_medium_lights->enable ( GL_CULL_FACE ) ; rwy_white_medium_lights->enable( GL_TEXTURE_2D ); @@ -267,7 +263,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char // hard coded runway low intensity white light state tex_name = gen_standard_dir_light_map( 235, 235, 195, 155 ); ssgSimpleState *rwy_white_low_lights = new ssgSimpleState(); - rwy_white_low_lights->ref(); rwy_white_low_lights->disable( GL_LIGHTING ); rwy_white_low_lights->enable ( GL_CULL_FACE ) ; rwy_white_low_lights->enable( GL_TEXTURE_2D ); @@ -285,7 +280,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char // hard coded runway yellow light state tex_name = gen_standard_dir_light_map( 235, 215, 20, 255 ); ssgSimpleState *rwy_yellow_lights = new ssgSimpleState(); - rwy_yellow_lights->ref(); rwy_yellow_lights->disable( GL_LIGHTING ); rwy_yellow_lights->enable ( GL_CULL_FACE ) ; rwy_yellow_lights->enable( GL_TEXTURE_2D ); @@ -302,7 +296,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char // hard coded runway medium intensity yellow light state tex_name = gen_standard_dir_light_map( 235, 215, 20, 205 ); ssgSimpleState *rwy_yellow_medium_lights = new ssgSimpleState(); - rwy_yellow_medium_lights->ref(); rwy_yellow_medium_lights->disable( GL_LIGHTING ); rwy_yellow_medium_lights->enable ( GL_CULL_FACE ) ; rwy_yellow_medium_lights->enable( GL_TEXTURE_2D ); @@ -320,7 +313,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char // hard coded runway low intensity yellow light state tex_name = gen_standard_dir_light_map( 235, 215, 20, 155 ); ssgSimpleState *rwy_yellow_low_lights = new ssgSimpleState(); - rwy_yellow_low_lights->ref(); rwy_yellow_low_lights->disable( GL_LIGHTING ); rwy_yellow_low_lights->enable ( GL_CULL_FACE ) ; rwy_yellow_low_lights->enable( GL_TEXTURE_2D ); @@ -338,7 +330,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char // hard coded runway red light state tex_name = gen_standard_dir_light_map( 235, 90, 90, 255 ); ssgSimpleState *rwy_red_lights = new ssgSimpleState(); - rwy_red_lights->ref(); rwy_red_lights->disable( GL_LIGHTING ); rwy_red_lights->enable ( GL_CULL_FACE ) ; rwy_red_lights->enable( GL_TEXTURE_2D ); @@ -356,7 +347,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char // hard coded medium intensity runway red light state tex_name = gen_standard_dir_light_map( 235, 90, 90, 205 ); ssgSimpleState *rwy_red_medium_lights = new ssgSimpleState(); - rwy_red_medium_lights->ref(); rwy_red_medium_lights->disable( GL_LIGHTING ); rwy_red_medium_lights->enable ( GL_CULL_FACE ) ; rwy_red_medium_lights->enable( GL_TEXTURE_2D ); @@ -374,7 +364,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char // hard coded low intensity runway red light state tex_name = gen_standard_dir_light_map( 235, 90, 90, 155 ); ssgSimpleState *rwy_red_low_lights = new ssgSimpleState(); - rwy_red_low_lights->ref(); rwy_red_low_lights->disable( GL_LIGHTING ); rwy_red_low_lights->enable ( GL_CULL_FACE ) ; rwy_red_low_lights->enable( GL_TEXTURE_2D ); @@ -392,7 +381,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char // hard coded runway green light state tex_name = gen_standard_dir_light_map( 20, 235, 20, 255 ); ssgSimpleState *rwy_green_lights = new ssgSimpleState(); - rwy_green_lights->ref(); rwy_green_lights->disable( GL_LIGHTING ); rwy_green_lights->enable ( GL_CULL_FACE ) ; rwy_green_lights->enable( GL_TEXTURE_2D ); @@ -410,7 +398,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char // hard coded medium intensity runway green light state tex_name = gen_standard_dir_light_map( 20, 235, 20, 205 ); ssgSimpleState *rwy_green_medium_lights = new ssgSimpleState(); - rwy_green_medium_lights->ref(); rwy_green_medium_lights->disable( GL_LIGHTING ); rwy_green_medium_lights->enable ( GL_CULL_FACE ) ; rwy_green_medium_lights->enable( GL_TEXTURE_2D ); @@ -428,7 +415,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char // hard coded low intensity runway green light state tex_name = gen_standard_dir_light_map( 20, 235, 20, 155 ); ssgSimpleState *rwy_green_low_lights = new ssgSimpleState(); - rwy_green_low_lights->ref(); rwy_green_low_lights->disable( GL_LIGHTING ); rwy_green_low_lights->enable ( GL_CULL_FACE ) ; rwy_green_low_lights->enable( GL_TEXTURE_2D ); @@ -448,7 +434,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char // hard coded low intensity taxiway blue light state tex_name = gen_taxiway_dir_light_map( 90, 90, 235, 205 ); ssgSimpleState *taxiway_blue_low_lights = new ssgSimpleState(); - taxiway_blue_low_lights->ref(); taxiway_blue_low_lights->disable( GL_LIGHTING ); taxiway_blue_low_lights->enable ( GL_CULL_FACE ) ; taxiway_blue_low_lights->enable( GL_TEXTURE_2D ); @@ -466,7 +451,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char // hard coded runway vasi light state tex_name = gen_standard_dir_light_map( 235, 235, 195, 255 ); ssgSimpleState *rwy_vasi_lights = new ssgSimpleState(); - rwy_vasi_lights->ref(); rwy_vasi_lights->disable( GL_LIGHTING ); rwy_vasi_lights->enable ( GL_CULL_FACE ) ; rwy_vasi_lights->enable( GL_TEXTURE_2D ); @@ -515,13 +499,11 @@ bool SGMaterialLib::add_item ( const string &mat_name, const string &full_path ) // Load a library of material properties bool SGMaterialLib::add_item ( const string &mat_name, ssgSimpleState *state ) { - SGMaterial *m = new SGMaterial( state ); + matlib[mat_name] = new SGMaterial( state ); SG_LOG( SG_TERRAIN, SG_INFO, " Loading material given a premade " << "ssgSimpleState = " << mat_name ); - matlib[mat_name] = m; - return true; } @@ -541,14 +523,6 @@ SGMaterial *SGMaterialLib::find( const string& material ) { // Destructor SGMaterialLib::~SGMaterialLib ( void ) { - // Free up all the material entries first - for ( material_map_iterator it = begin(); it != end(); it++ ) { - SGMaterial *slot = it->second; - slot->deRef(); - if ( slot->getRef() <= 0 ) { - delete slot; - } - } } diff --git a/simgear/scene/material/matlib.hxx b/simgear/scene/material/matlib.hxx index f457d276..44a12ff7 100644 --- a/simgear/scene/material/matlib.hxx +++ b/simgear/scene/material/matlib.hxx @@ -31,6 +31,8 @@ #include +#include + #include STL_STRING // Standard C++ string library #include // STL associative "array" #include // STL "array" @@ -52,7 +54,7 @@ class SGMaterialLib { private: // associative array of materials - typedef map < string, SGMaterial *, less > material_map; + typedef map < string, SGSharedPtr, less > material_map; typedef material_map::iterator material_map_iterator; typedef material_map::const_iterator const_material_map_iterator; diff --git a/simgear/scene/material/matmodel.cxx b/simgear/scene/material/matmodel.cxx index 259789d4..177f5ec4 100644 --- a/simgear/scene/material/matmodel.cxx +++ b/simgear/scene/material/matmodel.cxx @@ -108,12 +108,6 @@ SGMatModel::SGMatModel (const SGPropertyNode * node, double range_m) SGMatModel::~SGMatModel () { - for (unsigned int i = 0; i < _models.size(); i++) { - if (_models[i] != 0) { - ssgDeRefDelete(_models[i]); - _models[i] = 0; - } - } } int @@ -160,7 +154,6 @@ SGMatModel::load_models ( SGModelLib *modellib, // there). float ranges[] = {0, _range_m}; ssgRangeSelector * lod = new ssgRangeSelector; - lod->ref(); lod->setRanges(ranges, 2); if (_heading_type == HEADING_BILLBOARD) { // if the model is a billboard, it is likely : @@ -246,10 +239,6 @@ SGMatModelGroup::SGMatModelGroup (SGPropertyNode * node) SGMatModelGroup::~SGMatModelGroup () { - for (unsigned int i = 0; i < _objects.size(); i++) { - delete _objects[i]; - _objects[i] = 0; - } } double diff --git a/simgear/scene/material/matmodel.hxx b/simgear/scene/material/matmodel.hxx index 145f3aff..b303ef9e 100644 --- a/simgear/scene/material/matmodel.hxx +++ b/simgear/scene/material/matmodel.hxx @@ -35,6 +35,9 @@ #include #include +#include +#include +#include #include SG_USING_STD(string); @@ -53,7 +56,7 @@ class SGModelLib; * different shapes of trees), but they are considered equivalent * and interchangeable. */ -class SGMatModel { +class SGMatModel : public SGReferenced { public: @@ -116,14 +119,14 @@ public: */ HeadingType get_heading_type () const; + virtual ~SGMatModel (); + protected: friend class SGMatModelGroup; SGMatModel (const SGPropertyNode * node, double range_m); - virtual ~SGMatModel (); - private: /** @@ -138,7 +141,7 @@ private: double sim_time_sec ); vector _paths; - mutable vector _models; + mutable vector > _models; mutable bool _models_loaded; double _coverage_m2; double _range_m; @@ -154,7 +157,7 @@ private: * Each SGMaterial instance keeps a (possibly-empty) list of * object groups for placing randomly on the scenery. */ -class SGMatModelGroup { +class SGMatModelGroup : public SGReferenced { public: @@ -194,7 +197,7 @@ protected: private: double _range_m; - vector _objects; + vector > _objects; }; diff --git a/simgear/scene/model/placement.hxx b/simgear/scene/model/placement.hxx index 1b7a4c26..1b6654fe 100644 --- a/simgear/scene/model/placement.hxx +++ b/simgear/scene/model/placement.hxx @@ -16,6 +16,7 @@ #include #include +#include // Don't pull in the headers, since we don't need them here. @@ -91,8 +92,8 @@ private: double _pitch_deg; double _heading_deg; - ssgSelector * _selector; - ssgPlacementTransform * _position; + ssgSharedPtr _selector; + ssgSharedPtr _position; // Location SGLocation * _location; diff --git a/simgear/scene/sky/cloud.cxx b/simgear/scene/sky/cloud.cxx index f4b3de25..4652474e 100644 --- a/simgear/scene/sky/cloud.cxx +++ b/simgear/scene/sky/cloud.cxx @@ -31,6 +31,7 @@ #include #include #include +#include #include "newcloud.hxx" #include "cloudfield.hxx" @@ -49,12 +50,12 @@ #endif -static ssgStateSelector *layer_states[SGCloudLayer::SG_MAX_CLOUD_COVERAGES]; +static ssgSharedPtr layer_states[SGCloudLayer::SG_MAX_CLOUD_COVERAGES]; static bool state_initialized = false; static bool bump_mapping = false; static GLint nb_texture_unit = 0; -static ssgTexture *normal_map[SGCloudLayer::SG_MAX_CLOUD_COVERAGES][2] = { 0 }; -static ssgTexture *color_map[SGCloudLayer::SG_MAX_CLOUD_COVERAGES][2] = { 0 }; +static ssgSharedPtr normal_map[SGCloudLayer::SG_MAX_CLOUD_COVERAGES][2]; +static ssgSharedPtr color_map[SGCloudLayer::SG_MAX_CLOUD_COVERAGES][2]; static GLuint normalization_cube_map; static glActiveTextureProc glActiveTexturePtr = 0; @@ -345,56 +346,44 @@ SGCloudLayer::rebuild() cloud_path.set(texture_path.str()); cloud_path.append("overcast.rgb"); color_map[ SG_CLOUD_OVERCAST ][ 0 ] = new ssgTexture( cloud_path.str().c_str() ); - color_map[ SG_CLOUD_OVERCAST ][ 0 ]->ref(); cloud_path.set(texture_path.str()); cloud_path.append("overcast_n.rgb"); normal_map[ SG_CLOUD_OVERCAST ][ 0 ] = new ssgTexture( cloud_path.str().c_str() ); - normal_map[ SG_CLOUD_OVERCAST ][ 0 ]->ref(); cloud_path.set(texture_path.str()); cloud_path.append("overcast_top.rgb"); color_map[ SG_CLOUD_OVERCAST ][ 1 ] = new ssgTexture( cloud_path.str().c_str() ); - color_map[ SG_CLOUD_OVERCAST ][ 1 ]->ref(); cloud_path.set(texture_path.str()); cloud_path.append("overcast_top_n.rgb"); normal_map[ SG_CLOUD_OVERCAST ][ 1 ] = new ssgTexture( cloud_path.str().c_str() ); - normal_map[ SG_CLOUD_OVERCAST ][ 1 ]->ref(); cloud_path.set(texture_path.str()); cloud_path.append("broken.rgba"); color_map[ SG_CLOUD_BROKEN ][ 0 ] = new ssgTexture( cloud_path.str().c_str() ); - color_map[ SG_CLOUD_BROKEN ][ 0 ]->ref(); cloud_path.set(texture_path.str()); cloud_path.append("broken_n.rgb"); normal_map[ SG_CLOUD_BROKEN ][ 0 ] = new ssgTexture( cloud_path.str().c_str() ); - normal_map[ SG_CLOUD_BROKEN ][ 0 ]->ref(); cloud_path.set(texture_path.str()); cloud_path.append("scattered.rgba"); color_map[ SG_CLOUD_SCATTERED ][ 0 ] = new ssgTexture( cloud_path.str().c_str() ); - color_map[ SG_CLOUD_SCATTERED ][ 0 ]->ref(); cloud_path.set(texture_path.str()); cloud_path.append("scattered_n.rgb"); normal_map[ SG_CLOUD_SCATTERED ][ 0 ] = new ssgTexture( cloud_path.str().c_str() ); - normal_map[ SG_CLOUD_SCATTERED ][ 0 ]->ref(); cloud_path.set(texture_path.str()); cloud_path.append("few.rgba"); color_map[ SG_CLOUD_FEW ][ 0 ] = new ssgTexture( cloud_path.str().c_str() ); - color_map[ SG_CLOUD_FEW ][ 0 ]->ref(); cloud_path.set(texture_path.str()); cloud_path.append("few_n.rgb"); normal_map[ SG_CLOUD_FEW ][ 0 ] = new ssgTexture( cloud_path.str().c_str() ); - normal_map[ SG_CLOUD_FEW ][ 0 ]->ref(); cloud_path.set(texture_path.str()); cloud_path.append("cirrus.rgba"); color_map[ SG_CLOUD_CIRRUS ][ 0 ] = new ssgTexture( cloud_path.str().c_str() ); - color_map[ SG_CLOUD_CIRRUS ][ 0 ]->ref(); cloud_path.set(texture_path.str()); cloud_path.append("cirrus_n.rgb"); normal_map[ SG_CLOUD_CIRRUS ][ 0 ] = new ssgTexture( cloud_path.str().c_str() ); - normal_map[ SG_CLOUD_CIRRUS ][ 0 ]->ref(); glGenTextures( 1, &normalization_cube_map ); glBindTexture( GL_TEXTURE_CUBE_MAP_ARB, normalization_cube_map ); @@ -410,7 +399,6 @@ SGCloudLayer::rebuild() ssgSimpleState *state; state_sel = new ssgStateSelector( 2 ); - state_sel->ref(); cloud_path.set(texture_path.str()); cloud_path.append("overcast.rgb"); state_sel->setStep( 0, sgCloudMakeState(cloud_path.str()) ); @@ -420,7 +408,6 @@ SGCloudLayer::rebuild() layer_states[SG_CLOUD_OVERCAST] = state_sel; state_sel = new ssgStateSelector( 2 ); - state_sel->ref(); cloud_path.set(texture_path.str()); cloud_path.append("broken.rgba"); state = sgCloudMakeState(cloud_path.str()); @@ -429,7 +416,6 @@ SGCloudLayer::rebuild() layer_states[SG_CLOUD_BROKEN] = state_sel; state_sel = new ssgStateSelector( 2 ); - state_sel->ref(); cloud_path.set(texture_path.str()); cloud_path.append("scattered.rgba"); state = sgCloudMakeState(cloud_path.str()); @@ -438,7 +424,6 @@ SGCloudLayer::rebuild() layer_states[SG_CLOUD_SCATTERED] = state_sel; state_sel = new ssgStateSelector( 2 ); - state_sel->ref(); cloud_path.set(texture_path.str()); cloud_path.append("few.rgba"); state = sgCloudMakeState(cloud_path.str()); @@ -447,7 +432,6 @@ SGCloudLayer::rebuild() layer_states[SG_CLOUD_FEW] = state_sel; state_sel = new ssgStateSelector( 2 ); - state_sel->ref(); cloud_path.set(texture_path.str()); cloud_path.append("cirrus.rgba"); state = sgCloudMakeState(cloud_path.str()); diff --git a/simgear/scene/sky/newcloud.cxx b/simgear/scene/sky/newcloud.cxx index a527b792..f8453683 100644 --- a/simgear/scene/sky/newcloud.cxx +++ b/simgear/scene/sky/newcloud.cxx @@ -30,6 +30,7 @@ #include #include #include +#include #include STL_ALGORITHM #include SG_GLU_H @@ -41,7 +42,7 @@ /* */ -static ssgTexture *cloudTextures[SGNewCloud::CLTexture_max]; +static ssgSharedPtr cloudTextures[SGNewCloud::CLTexture_max]; bool SGNewCloud::useAnisotropic = true; @@ -129,12 +130,10 @@ void SGNewCloud::loadTextures(const string &tex_path) { cloud_path.set(tex_path); cloud_path.append("cl_cumulus.rgb"); cloudTextures[ CLTexture_cumulus ] = new ssgTexture( cloud_path.str().c_str(), false, false, false ); - cloudTextures[ CLTexture_cumulus ]->ref(); cloud_path.set(tex_path); cloud_path.append("cl_stratus.rgb"); cloudTextures[ CLTexture_stratus ] = new ssgTexture( cloud_path.str().c_str(), false, false, false ); - cloudTextures[ CLTexture_stratus ]->ref(); } diff --git a/simgear/sound/sample_openal.hxx b/simgear/sound/sample_openal.hxx index 381164b4..10625ad6 100644 --- a/simgear/sound/sample_openal.hxx +++ b/simgear/sound/sample_openal.hxx @@ -37,6 +37,8 @@ #include STL_STRING #include +#include +#include #include @@ -56,7 +58,7 @@ SG_USING_STD(string); * manages everything we need to know for an individual sound sample */ -class SGSoundSample { +class SGSoundSample : public SGReferenced { private: diff --git a/simgear/sound/soundmgr_openal.cxx b/simgear/sound/soundmgr_openal.cxx index 534c4430..971bea6d 100644 --- a/simgear/sound/soundmgr_openal.cxx +++ b/simgear/sound/soundmgr_openal.cxx @@ -141,15 +141,6 @@ SGSoundMgr::~SGSoundMgr() { if (context) alcDestroyContext( context ); #endif - // - // Remove the samples from the sample manager. - // - sample_map_iterator sample_current = samples.begin(); - sample_map_iterator sample_end = samples.end(); - for ( ; sample_current != sample_end; ++sample_current ) { - SGSoundSample *sample = sample_current->second; - delete sample; - } } @@ -158,12 +149,6 @@ void SGSoundMgr::init() { // // Remove the samples from the sample manager. // - sample_map_iterator sample_current = samples.begin(); - sample_map_iterator sample_end = samples.end(); - for ( ; sample_current != sample_end; ++sample_current ) { - SGSoundSample *sample = sample_current->second; - delete sample; - } samples.clear(); } diff --git a/simgear/sound/soundmgr_openal.hxx b/simgear/sound/soundmgr_openal.hxx index 6c0d1842..dd4d3913 100644 --- a/simgear/sound/soundmgr_openal.hxx +++ b/simgear/sound/soundmgr_openal.hxx @@ -56,7 +56,7 @@ SG_USING_STD(map); SG_USING_STD(string); -typedef map < string, SGSoundSample * > sample_map; +typedef map < string, SGSharedPtr > sample_map; typedef sample_map::iterator sample_map_iterator; typedef sample_map::const_iterator const_sample_map_iterator; diff --git a/simgear/sound/xmlsound.cxx b/simgear/sound/xmlsound.cxx index 3e27b82b..3bd9bd89 100644 --- a/simgear/sound/xmlsound.cxx +++ b/simgear/sound/xmlsound.cxx @@ -65,7 +65,6 @@ static const struct { SGXmlSound::SGXmlSound() : _sample(NULL), _condition(NULL), - _property(NULL), _active(false), _name(""), _mode(SGXmlSound::ONCE), @@ -80,12 +79,10 @@ SGXmlSound::~SGXmlSound() { _sample->stop(); - delete _property; delete _condition; _volume.clear(); _pitch.clear(); - delete _sample; } void diff --git a/simgear/sound/xmlsound.hxx b/simgear/sound/xmlsound.hxx index e290b393..ced1e046 100644 --- a/simgear/sound/xmlsound.hxx +++ b/simgear/sound/xmlsound.hxx @@ -120,7 +120,7 @@ protected: // SGXmlSound properties typedef struct { - SGPropertyNode * prop; + SGPropertyNode_ptr prop; double (*fn)(double); double *intern; double factor; @@ -133,10 +133,10 @@ protected: private: SGSoundMgr * _mgr; - SGSoundSample * _sample; + SGSharedPtr _sample; SGCondition * _condition; - SGPropertyNode * _property; + SGPropertyNode_ptr _property; bool _active; string _name;