@@ -144,7 +144,13 @@ namespace hal
144144 GridPlacement (const QHash<hal::Node,QPoint>& data) : QHash<hal::Node,QPoint>(data) {;}
145145
146146 void setGatePosition (u32 gateId, std::pair<int ,int >p, bool swap = false ) {
147- QPoint pos = QPoint (gatePosition (gateId)->first , gatePosition (gateId)->second ); // position of current gate to move
147+ std::pair<int ,int >* posPtr = gatePosition (gateId);
148+ if (!posPtr)
149+ {
150+ log_warning (" gui" , " Gate id {} cannot be moved, not found in current placement" , gateId);
151+ return ;
152+ }
153+ QPoint pos = QPoint (posPtr->first , posPtr->second ); // position of current gate to move
148154 hal::Node nd = key (QPoint (p.first , p.second )); // find the node in the destination
149155
150156 if (!nd.isNull () && !swap) // if the destination placement is not available
@@ -159,8 +165,15 @@ namespace hal
159165 else
160166 operator [](hal::Node (gateId,hal::Node::Gate)) = QPoint (p.first ,p.second );
161167 }
168+
162169 void setModulePosition (u32 moduleId, std::pair<int ,int >p, bool swap = false ){
163- QPoint pos = QPoint (modulePosition (moduleId)->first , modulePosition (moduleId)->second );
170+ std::pair<int ,int >* posPtr = modulePosition (moduleId);
171+ if (!posPtr)
172+ {
173+ log_warning (" gui" , " Module id {} cannot be moved, not found in current placement" , moduleId);
174+ return ;
175+ }
176+ QPoint pos = QPoint (posPtr->first , posPtr->second ); // position of current module to move
164177 hal::Node nd = key (QPoint (p.first , p.second ));
165178
166179 if (!nd.isNull () && !swap)
@@ -174,11 +187,13 @@ namespace hal
174187 }
175188 else
176189 operator [](hal::Node (moduleId,hal::Node::Module)) = QPoint (p.first ,p.second );};
190+
177191 std::pair<int ,int >* gatePosition (u32 gateId) const
178192 {
179193 auto it = constFind (hal::Node (gateId,hal::Node::Gate));
180194 return (it == constEnd () ? nullptr : new std::pair<int ,int >(it->x (),it->y ()));
181195 }
196+
182197 std::pair<int ,int >* modulePosition (u32 moduleId) const
183198 {
184199 auto it = constFind (hal::Node (moduleId,hal::Node::Module));
0 commit comments