diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-05-15 11:53:46 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-05-15 11:53:46 +1000 |
commit | 625f0d8fc58d2786624f5812370f328e8d710460 (patch) | |
tree | 2446345c4dc5e3c0f0a9b62c00eee18ff381eee9 /source/frontend/StarWireInterface.cpp | |
parent | 2f2c08a8dc796fb35a15ba0bca4dc7df720b6bfc (diff) |
don't crash when drawing wires connected to a non-existent node
Diffstat (limited to 'source/frontend/StarWireInterface.cpp')
-rw-r--r-- | source/frontend/StarWireInterface.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/source/frontend/StarWireInterface.cpp b/source/frontend/StarWireInterface.cpp index 5382cbb..f444e88 100644 --- a/source/frontend/StarWireInterface.cpp +++ b/source/frontend/StarWireInterface.cpp @@ -99,6 +99,7 @@ void WirePane::renderImpl() { auto region = RectF(m_worldClient->clientWindow()); auto const& camera = m_worldPainter->camera(); + auto badWire = Color::rgbf(0.6f + (float)sin(Time::monotonicTime() * Constants::pi * 2.0) * 0.4f, 0.0f, 0.0f); auto highWire = Color::Red; auto lowWire = Color::Red.mix(Color::Black, 0.8f); auto white = Color::White.toRgba(); @@ -137,9 +138,13 @@ void WirePane::renderImpl() { auto wire = lowWire; Vec2I outPosition = connection.entityLocation; if (auto sourceEntity = m_worldClient->atTile<WireEntity>(connection.entityLocation).get(0)) { - outPosition += sourceEntity->nodePosition({WireDirection::Output, connection.nodeIndex}); - if (sourceEntity->nodeState(WireNode{WireDirection::Output, connection.nodeIndex})) - wire = highWire; + if (connection.nodeIndex < sourceEntity->nodeCount(WireDirection::Output)) { + outPosition += sourceEntity->nodePosition({WireDirection::Output, connection.nodeIndex}); + if (sourceEntity->nodeState(WireNode{WireDirection::Output, connection.nodeIndex})) + wire = highWire; + } else { + wire = badWire; + } } renderWire(centerOfTile(inPosition), centerOfTile(outPosition), wire); @@ -158,8 +163,12 @@ void WirePane::renderImpl() { visitedConnections.contains({connection, {tilePosition, i}}); Vec2I inPosition = connection.entityLocation; - if (auto sourceEntity = m_worldClient->atTile<WireEntity>(connection.entityLocation).get(0)) - inPosition += sourceEntity->nodePosition({WireDirection::Input, connection.nodeIndex}); + if (auto sourceEntity = m_worldClient->atTile<WireEntity>(connection.entityLocation).get(0)) { + if (connection.nodeIndex < sourceEntity->nodeCount(WireDirection::Input)) + inPosition += sourceEntity->nodePosition({WireDirection::Input, connection.nodeIndex}); + else + wire = badWire; + } renderWire(centerOfTile(outPosition), centerOfTile(inPosition), wire); } |