} else {
return true;
}
-
-#if 0
- cout << path << " ";
- FILE *fp = fopen( path.c_str(), "r" );
- if ( fp == NULL ) {
- cout << " doesn't exist\n";
- return false;
- } else {
- cout << " exists\n";
- return true;
- }
-#endif
}
FGNewMat *m = matlib[src_mat];
if ( m != NULL ) {
matlib[dst_mat] = m;
+ m->ref();
} else {
SG_LOG( SG_GENERAL, SG_ALERT,
"Bad material alias pointing to nonexistant material" );
// create a pointer to a heap allocated copy of the structure
FGNewMat *m = new FGNewMat;
*m = tmp;
+ m->ref();
// build the ssgSimpleState
SGPath tex_path( globals->get_fg_root() );
// Free up all the material entries first
for ( material_map_iterator it = begin(); it != end(); it++ ) {
FGNewMat *slot = it->second;
- if ( slot != NULL ) {
+ slot->deRef();
+ if ( slot->getRef() <= 0 ) {
delete slot;
- it->second = NULL;
}
}
}
// true if texture loading deferred, and not yet loaded
bool texture_loaded;
+ // ref count so we can properly delete if we have multiple
+ // pointers to this record
+ int refcount;
+
public:
// Constructor
inline ssgStateSelector *get_state() const { return state; }
+ inline void ref() { refcount++; }
+ inline void deRef() { refcount--; }
+ inline int getRef() const { return refcount; }
+
void dump_info();
};