From a997dab769d590fdb03373aad45f90a4ecf6b23a Mon Sep 17 00:00:00 2001
From: John Beard <john.j.beard@gmail.com>
Date: Thu, 16 Jan 2025 20:48:04 +0800
Subject: [PATCH] Position interactive: add re-entrancy guard

---
 pcbnew/tools/position_relative_tool.cpp | 8 +++++++-
 pcbnew/tools/position_relative_tool.h   | 1 +
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/pcbnew/tools/position_relative_tool.cpp b/pcbnew/tools/position_relative_tool.cpp
index 885238595b..415913addc 100644
--- a/pcbnew/tools/position_relative_tool.cpp
+++ b/pcbnew/tools/position_relative_tool.cpp
@@ -84,7 +84,8 @@ static void positionRelativeClientSelectionFilter( const VECTOR2I&     aPt,
 POSITION_RELATIVE_TOOL::POSITION_RELATIVE_TOOL() :
     PCB_TOOL_BASE( "pcbnew.PositionRelative" ),
     m_dialog( nullptr ),
-    m_selectionTool( nullptr )
+    m_selectionTool( nullptr ),
+    m_inInteractivePosition( false )
 {
 }
 
@@ -158,6 +159,11 @@ int POSITION_RELATIVE_TOOL::PositionRelative( const TOOL_EVENT& aEvent )
 
 int POSITION_RELATIVE_TOOL::PositionRelativeInteractively( const TOOL_EVENT& aEvent )
 {
+    if( m_inInteractivePosition )
+        return false;
+
+    REENTRANCY_GUARD guard( &m_inInteractivePosition );
+
     // First, acquire the selection that we will be moving after
     // we have the new offset vector.
     const auto& selection = m_selectionTool->RequestSelection(
diff --git a/pcbnew/tools/position_relative_tool.h b/pcbnew/tools/position_relative_tool.h
index 8ccdc781ca..79a0214c41 100644
--- a/pcbnew/tools/position_relative_tool.h
+++ b/pcbnew/tools/position_relative_tool.h
@@ -82,6 +82,7 @@ private:
     PCB_SELECTION_TOOL*           m_selectionTool;
     PCB_SELECTION                 m_selection;
     VECTOR2I                      m_selectionAnchor;
+    bool                          m_inInteractivePosition; // Re-entrancy guard
 
     std::unique_ptr<BOARD_COMMIT> m_commit;
 };