From a72d99821adaa1b8f50054c882412dc93b297258 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 27 Dec 2022 19:46:32 +0000 Subject: [PATCH] Fix crash on hovering link graph link where both ends have same position See: #468 --- src/linkgraph/linkgraph_gui.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp index d84bbb12c0..a304e197b3 100644 --- a/src/linkgraph/linkgraph_gui.cpp +++ b/src/linkgraph/linkgraph_gui.cpp @@ -506,7 +506,9 @@ bool LinkGraphOverlay::ShowTooltip(Point pt, TooltipCloseCondition close_cond) /* Check the distance from the cursor to the line defined by the two stations. */ auto check_distance = [&]() -> bool { int64 a = ((ptb.x - pta.x) * (pta.y - pt.y) - (pta.x - pt.x) * (ptb.y - pta.y)); - return ((a * a) / ((ptb.x - pta.x) * (ptb.x - pta.x) + (ptb.y - pta.y) * (ptb.y - pta.y))) <= 16; + int64 b = ((ptb.x - pta.x) * (ptb.x - pta.x) + (ptb.y - pta.y) * (ptb.y - pta.y)); + if (b == 0) return false; + return ((a * a) / b) <= 16; }; const auto &link = i->prop; if ((link.Usage() > 0 || (_ctrl_pressed && link.capacity > 0)) &&