From 7da609f539040d11cccc61b838f4b74e06135552 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 27 Aug 2016 02:29:16 +0300 Subject: [PATCH] Do not attempt to unwatch a mesh that was already removed --- source/object.cpp | 20 ++++++++++++++++---- source/object.h | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/source/object.cpp b/source/object.cpp index f043f614..a27553a6 100644 --- a/source/object.cpp +++ b/source/object.cpp @@ -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 &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) diff --git a/source/object.h b/source/object.h index a11bfd9b..3d0415c6 100644 --- a/source/object.h +++ b/source/object.h @@ -72,6 +72,7 @@ private: std::vector lods; Geometry::BoundingSphere 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 -- 2.43.0