From ab031cf34099562e00783825da9930e3c226803b Mon Sep 17 00:00:00 2001 From: brunoherbelin Date: Sat, 15 Aug 2020 22:40:12 +0200 Subject: [PATCH] Fixed deletion of clone: remove from origin!!! --- Source.cpp | 15 ++++++++++----- Source.h | 8 +++++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Source.cpp b/Source.cpp index 4786326..ffd32a9 100644 --- a/Source.cpp +++ b/Source.cpp @@ -133,6 +133,11 @@ Source::Source() : initialized_(false), active_(true), need_update_(true) Source::~Source() { + // inform clones that they lost their origin + for (auto it = clones_.begin(); it != clones_.end(); it++) + (*it)->unlink(); + clones_.clear(); + // delete objects delete stored_status_; if (renderbuffer_) @@ -150,10 +155,6 @@ Source::~Source() frames_.clear(); overlays_.clear(); - // inform clones that they lost their origin - for (auto it = clones_.begin(); it != clones_.end(); it++) - (*it)->origin_ = nullptr; - // don't forget that the processing shader // could be created but not used if ( renderingshader_ != processingshader_ ) @@ -401,6 +402,7 @@ CloneSource *Source::clone() return s; } + CloneSource::CloneSource(Source *origin) : Source(), origin_(origin) { // create surface: @@ -409,6 +411,9 @@ CloneSource::CloneSource(Source *origin) : Source(), origin_(origin) CloneSource::~CloneSource() { + if (origin_) + origin_->clones_.remove(this); + // delete surface if (clonesurface_) delete clonesurface_; @@ -478,7 +483,7 @@ void CloneSource::render() { if (!initialized_) init(); - else { + else if (origin_) { // render the view into frame buffer static glm::mat4 projection = glm::ortho(-1.f, 1.f, 1.f, -1.f, -1.f, 1.f); renderbuffer_->begin(); diff --git a/Source.h b/Source.h index 62bef97..3a2d5cf 100644 --- a/Source.h +++ b/Source.h @@ -3,6 +3,7 @@ #include #include +#include #include #include "View.h" @@ -24,6 +25,7 @@ typedef std::list CloneList; class Source { + friend class CloneSource; friend class View; friend class MixingView; friend class GeometryView; @@ -43,7 +45,10 @@ public: // cloning mechanism virtual CloneSource *clone (); - inline size_t numClones() const { return clones_.size(); } +// void unClone(CloneSource *clone); +// inline size_t numClones() const { return clones_.size(); } +// inline CloneList::iterator beginClones () { return clones_.begin(); } +// inline CloneList::iterator endClones () { return clones_.end(); } // Display mode typedef enum { @@ -190,6 +195,7 @@ public: void accept (Visitor& v) override; CloneSource *clone() override; + inline void unlink() { origin_ = nullptr; } inline Source *origin() const { return origin_; } protected: