Skip to content

Commit

Permalink
Fix object self-connecting after removing it from a connection
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed Feb 16, 2025
1 parent b038cc9 commit fd3d93a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 3 additions & 5 deletions Source/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1089,9 +1089,8 @@ void Object::mouseDrag(MouseEvent const& e)

if (checkedOut && checkedIn) {
cnv->patch.removeConnection(checkedOut, c->outIdx, checkedIn, c->inIdx, c->getPathState());

cnv->connections.add(cnv, outlet, c->inlet, nullptr);
cnv->connections.remove_one(c);
cnv->connections.add(cnv, outlet, c->inlet, nullptr);
}
}

Expand Down Expand Up @@ -1161,8 +1160,8 @@ void Object::mouseDrag(MouseEvent const& e)
if (object->numInputs && object->numOutputs && !object->iolets.empty()) {
bool intersected = false;
for (auto* connection : cnv->connections) {

if (connection->intersectsRectangle(object->iolets[0]->getCanvasBounds())) {
if (connection->intersectsRectangle(object->iolets[0]->getCanvasBounds()) &&
!iolets.contains(connection->inlet) && !iolets.contains(connection->outlet)) {
object->iolets[0]->isTargeted = true;
object->iolets[object->numInputs]->isTargeted = true;
object->iolets[0]->repaint();
Expand All @@ -1173,7 +1172,6 @@ void Object::mouseDrag(MouseEvent const& e)
break;
}
}

if (!intersected) {
object->iolets[0]->isTargeted = false;
object->iolets[object->numInputs]->isTargeted = false;
Expand Down
6 changes: 6 additions & 0 deletions Source/Utility/Containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2233,6 +2233,12 @@ class PooledPtrArray {
return data_.back();
}

template<typename U>
[[nodiscard]] bool contains(U const& to_find) const
{
return std::find(this->begin(), this->end(), to_find) != this->end();
}

// Other necessary methods, simplified
bool empty() const { return data_.empty(); }
bool not_empty() const { return !data_.empty(); }
Expand Down

0 comments on commit fd3d93a

Please sign in to comment.