]> git.tdb.fi Git - libs/gl.git/commitdiff
Do not attempt to unwatch a mesh that was already removed
authorMikko Rasa <tdb@tdb.fi>
Fri, 26 Aug 2016 23:29:16 +0000 (02:29 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 26 Aug 2016 23:29:16 +0000 (02:29 +0300)
source/object.cpp
source/object.h

index f043f614ac84f80e549381b003b3202f8231c02f..a27553a6236e029c27cfe547304b00e84371f5e5 100644 (file)
@@ -18,11 +18,13 @@ namespace Msp {
 namespace GL {
 
 Object::Object():
-       lods(1)
+       lods(1),
+       lod0_watched(false)
 { }
 
 Object::Object(const Mesh *m, const Technique *t):
-       lods(1)
+       lods(1),
+       lod0_watched(false)
 {
        set_mesh(m);
        set_technique(t);
@@ -30,7 +32,7 @@ Object::Object(const Mesh *m, const Technique *t):
 
 Object::~Object()
 {
-       if(lods[0].mesh)
+       if(lods[0].mesh && lod0_watched)
                if(ResourceManager *rm = lods[0].mesh->get_manager())
                        rm->unwatch_resource(*lods[0].mesh, *this);
 }
@@ -51,15 +53,19 @@ Object::LevelOfDetail &Object::get_lod(unsigned i, const char *caller)
 void Object::set_mesh(unsigned i, const Mesh *m)
 {
        RefPtr<const Mesh> &ptr = get_lod(i, "Object::set_mesh").mesh;
-       if(i==0 && ptr)
+       if(i==0 && ptr && lod0_watched)
                if(ResourceManager *rm = ptr->get_manager())
                        rm->unwatch_resource(*ptr, *this);
        ptr = m;
        ptr.keep();
+       lod0_watched = false;
 
        if(i==0 && m)
                if(ResourceManager *rm = m->get_manager())
+               {
                        rm->watch_resource(*m, *this);
+                       lod0_watched = true;
+               }
 
        update_bounding_sphere();
 }
@@ -186,6 +192,12 @@ void Object::resource_loaded(Resource &res)
                update_bounding_sphere();
 }
 
+void Object::resource_removed(Resource &res)
+{
+       if(&res==lods.front().mesh.get())
+               lod0_watched = false;
+}
+
 
 Object::Loader::Loader(Object &o):
        LodLoader(o, 0, 0)
index a11bfd9b654d0ffa98887fefcb2c886a360e1d98..3d0415c66daa64b3c8ebb3436b0da037897912e9 100644 (file)
@@ -72,6 +72,7 @@ private:
 
        std::vector<LevelOfDetail> lods;
        Geometry::BoundingSphere<float, 3> bounding_sphere;
+       bool lod0_watched;
 
 public:
        Object();
@@ -122,6 +123,7 @@ private:
        const RenderPass *get_pass(const Tag &, unsigned) const;
 
        virtual void resource_loaded(Resource &);
+       virtual void resource_removed(Resource &);
 };
 
 } // namespace GL