Skip to content

Commit 2f20cca

Browse files
shimatclaude
andcommitted
Only remove a Window's own entry from the static registry on Dispose
TryRemove(name, out _) deleted whatever instance currently occupied that key, regardless of identity. If a second Window reused a name before the first was disposed (Windows[name] = this in the constructor lets that happen intentionally), disposing the first one would evict the second, still-live window from the registry even though it's unaffected. Use the ICollection<KeyValuePair<,>> overload of Remove, which only deletes the entry when both the key and the value (reference identity) match. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 28831ba commit 2f20cca

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/OpenCvSharp/Modules/highgui/Window.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ public void Dispose()
8080
return;
8181
IsDisposed = true;
8282

83-
Windows.TryRemove(name, out _);
83+
// Only remove the map entry if it still points at this instance: another Window may have
84+
// since reused the same name (see the constructor), and that instance's entry must survive.
85+
((ICollection<KeyValuePair<string, Window>>) Windows).Remove(new KeyValuePair<string, Window>(name, this));
8486
trackbars.Clear();
8587

8688
// Destroying the window also releases OpenCV's references to its mouse/trackbar

0 commit comments

Comments
 (0)