From 622ed4d26f398fdc1b921179c3908c0662667829 Mon Sep 17 00:00:00 2001 From: Martin Date: Sat, 19 Jul 2025 09:10:27 +0200 Subject: [PATCH] IDE, Debugger: fixed accessing freed watch (inspect, evel, mem-view might clear there Watch-collection, but the watch was still notified to all other windows / they will ignore it, as it isn't theirs, but the call GetTopWatch) --- ide/packages/idedebugger/debugger.pp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/ide/packages/idedebugger/debugger.pp b/ide/packages/idedebugger/debugger.pp index 09e9b3c57c..3bb7c54654 100644 --- a/ide/packages/idedebugger/debugger.pp +++ b/ide/packages/idedebugger/debugger.pp @@ -523,6 +523,8 @@ type TWatchesNotificationList = class(TDebuggerNotificationList) private + FCurWatch: TCurrentWatch; + procedure DoWatchFreed(Sender: TObject); function GetItem(AIndex: Integer): TWatchesNotification; public procedure NotifyAdd(const ASender: TCurrentWatches; const AWatch: TCurrentWatch); @@ -4923,6 +4925,12 @@ begin Result := TWatchesNotification(FList[AIndex]); end; +procedure TWatchesNotificationList.DoWatchFreed(Sender: TObject); +begin + if Sender = FCurWatch then + FCurWatch := nil; +end; + procedure TWatchesNotificationList.NotifyAdd(const ASender: TCurrentWatches; const AWatch: TCurrentWatch); var @@ -4940,9 +4948,19 @@ var i: LongInt; begin i := Count; - while NextDownIndex(i) do - if Assigned(Items[i].OnUpdate) then + FCurWatch := AWatch; + if FCurWatch <> nil then + FCurWatch.AddFreeNotification(@DoWatchFreed); + while NextDownIndex(i) do begin + if Assigned(Items[i].OnUpdate) then begin Items[i].OnUpdate(ASender, AWatch); + if (AWatch <> nil) and (FCurWatch = nil) then + break; // watch got freed + end; + end; + if FCurWatch <> nil then + AWatch.RemoveFreeNotification(@DoWatchFreed); + FCurWatch := nil; end; procedure TWatchesNotificationList.NotifyRemove(const ASender: TCurrentWatches;