@@ -110,21 +110,18 @@ bool DataFlowGraphModel::connectionPossible(ConnectionId const connectionId) con
110110 return false ;
111111 }
112112
113- // Check port bounds
113+ // Check port bounds, i.e. that we do not connect non-existing port numbers
114114 auto checkPortBounds = [&](PortType const portType) {
115115 NodeId const nodeId = getNodeId (portType, connectionId);
116- PortIndex const portIndex = getPortIndex (portType, connectionId);
117-
118- auto it = _models.find (nodeId);
119- if (it == _models.end ()) return false ;
120-
121- unsigned int portCount = it->second ->nPorts (portType);
122- return portIndex < portCount;
123- };
116+ auto portCountRole = (portType == PortType::Out) ?
117+ NodeRole::OutPortCount :
118+ NodeRole::InPortCount;
124119
125- if (!checkPortBounds (PortType::Out) || !checkPortBounds (PortType::In)) {
126- return false ;
127- }
120+ std::size_t const portCount =
121+ nodeData (nodeId, portCountRole).toUInt ();
122+
123+ return getPortIndex (portType, connectionId) < portCount;
124+ };
128125
129126 auto getDataType = [&](PortType const portType) {
130127 return portData (getNodeId (portType, connectionId),
@@ -146,7 +143,10 @@ bool DataFlowGraphModel::connectionPossible(ConnectionId const connectionId) con
146143 };
147144
148145 return getDataType (PortType::Out).id == getDataType (PortType::In).id
149- && portVacant (PortType::Out) && portVacant (PortType::In);
146+ && portVacant (PortType::Out)
147+ && portVacant (PortType::In)
148+ && checkPortBounds (PortType::Out)
149+ && checkPortBounds (PortType::In);
150150}
151151
152152void DataFlowGraphModel::addConnection (ConnectionId const connectionId)
0 commit comments