From 5e4c5c969ab3bd0c0aa7313e5882346f5f315555 Mon Sep 17 00:00:00 2001
From: Seth Hillbrand <seth@kipro-pcb.com>
Date: Tue, 7 Jan 2025 15:52:10 -0800
Subject: [PATCH] Freeze ERC action before deleting

Each deletion of a marker adjusts the tree model and comes with a
possibility of a repaint, which can trigger a full screen repaint.
Keeping the dialog frozen prevents these updates

Fixes https://gitlab.com/kicad/code/kicad/-/issues/19531
---
 eeschema/dialogs/dialog_erc.cpp | 4 ++++
 pcbnew/dialogs/dialog_drc.cpp   | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/eeschema/dialogs/dialog_erc.cpp b/eeschema/dialogs/dialog_erc.cpp
index a63e71a643..d9ca026754 100644
--- a/eeschema/dialogs/dialog_erc.cpp
+++ b/eeschema/dialogs/dialog_erc.cpp
@@ -1010,12 +1010,16 @@ void DIALOG_ERC::OnSeverity( wxCommandEvent& aEvent )
 void DIALOG_ERC::deleteAllMarkers( bool aIncludeExclusions )
 {
     // Clear current selection list to avoid selection of deleted items
+    // Freeze to avoid repainting the dialog, which can cause a RePaint()
+    // of the screen as well
+    Freeze();
     m_parent->GetToolManager()->RunAction( EE_ACTIONS::clearSelection );
 
     m_markerTreeModel->DeleteItems( false, aIncludeExclusions, false );
 
     SCH_SCREENS screens( m_parent->Schematic().Root() );
     screens.DeleteAllMarkers( MARKER_BASE::MARKER_ERC, aIncludeExclusions );
+    Thaw();
 }
 
 
diff --git a/pcbnew/dialogs/dialog_drc.cpp b/pcbnew/dialogs/dialog_drc.cpp
index 4301f6f138..d6c97f2ebf 100644
--- a/pcbnew/dialogs/dialog_drc.cpp
+++ b/pcbnew/dialogs/dialog_drc.cpp
@@ -1175,6 +1175,7 @@ void DIALOG_DRC::ExcludeMarker()
 void DIALOG_DRC::deleteAllMarkers( bool aIncludeExclusions )
 {
     // Clear current selection list to avoid selection of deleted items
+    Freeze();
     m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear );
 
     m_markersTreeModel->DeleteItems( false, aIncludeExclusions, false );
@@ -1182,6 +1183,7 @@ void DIALOG_DRC::deleteAllMarkers( bool aIncludeExclusions )
     m_fpWarningsTreeModel->DeleteItems( false, aIncludeExclusions, false );
 
     m_frame->GetBoard()->DeleteMARKERs( true, aIncludeExclusions );
+    Thaw();
 }