Still the ownership problem. 5, why 5? It should be 3...

This commit is contained in:
Sebastian
2024-12-01 01:45:36 +01:00
parent b6a049ea0d
commit f926b95092
3 changed files with 15 additions and 4 deletions
+8 -3
View File
@@ -6,7 +6,7 @@
#include <vector> #include <vector>
namespace VISEQ::BASE { namespace VISEQ::BASE {
class Connectable : public Draggable { class Connectable : public Draggable, public std::enable_shared_from_this<Connectable> {
public: public:
Connectable() {} Connectable() {}
Connectable(Vec2Df position) : Draggable(position) {} Connectable(Vec2Df position) : Draggable(position) {}
@@ -19,6 +19,10 @@ namespace VISEQ::BASE {
bool connecting = false; bool connecting = false;
Vec2Df connecting_position; Vec2Df connecting_position;
std::shared_ptr<Connectable> getPtr(){
return shared_from_this();
}
virtual void init() { virtual void init() {
connectables.emplace_back(this); connectables.emplace_back(this);
} }
@@ -36,11 +40,12 @@ namespace VISEQ::BASE {
virtual void connect() { virtual void connect() {
if(picked_up){ if(picked_up){
for(auto c : connectables){ for(auto c : connectables){
if(c.get() != this && c->hovering()) { if(c != getPtr() && c->hovering()) {
partner = c; partner = c;
c->partner.reset(this); c->partner = getPtr();
new_partner = true; new_partner = true;
partner->new_partner = true; partner->new_partner = true;
std::cout << "connect use count: " << getPtr().use_count() << std::endl;
break; break;
} }
} }
+1 -1
View File
@@ -31,7 +31,7 @@ namespace VISEQ::GRAPH {
} }
std::shared_ptr<Connectable> getPtr(){ std::shared_ptr<Connectable> getPtr(){
return std::static_pointer_cast<Connector>(shared_from_this()); return std::static_pointer_cast<Connector>(BASE::Connectable::shared_from_this());
} }
virtual bool hovering() override { virtual bool hovering() override {
+6
View File
@@ -15,6 +15,7 @@
#include "node.h" #include "node.h"
#include <algorithm> #include <algorithm>
#include <cstddef>
#include <cstdio> #include <cstdio>
#include <iostream> #include <iostream>
#include <iterator> #include <iterator>
@@ -224,6 +225,11 @@ namespace VISEQ::GRAPH {
void removeEdges(){ void removeEdges(){
for(auto edge : remove_edges){ for(auto edge : remove_edges){
edge->start_conn->partner.reset();
std::cout << "connectors size: " << edge->start->connectors.size() << std::endl;
std::cout << "use count: " << edge->start_conn.use_count() << std::endl;
edge->start_conn.reset();
edge->end_conn.reset();
std::cout << "connectors size: " << edge->start->connectors.size() << std::endl; std::cout << "connectors size: " << edge->start->connectors.size() << std::endl;
std::cout << "use count: " << edge->start_conn.use_count() << std::endl; std::cout << "use count: " << edge->start_conn.use_count() << std::endl;
std::erase(edge->start->connectors, edge->start_conn); std::erase(edge->start->connectors, edge->start_conn);