1- using Intersect . Client . Framework . GenericClasses ;
1+ using System . Diagnostics ;
2+ using Intersect . Client . Framework . GenericClasses ;
23using Intersect . Client . Framework . Gwen . Anim ;
34using Intersect . Client . Framework . Gwen . DragDrop ;
45using Intersect . Client . Framework . Gwen . Input ;
@@ -15,8 +16,7 @@ namespace Intersect.Client.Framework.Gwen.Control;
1516/// </summary>
1617public partial class Canvas : Base
1718{
18-
19- private readonly List < IDisposable > mDisposeQueue ; // dictionary for faster access?
19+ private readonly List < IDisposable > _disposeQueue = [ ] ;
2020
2121 private Color mBackgroundColor ;
2222
@@ -48,8 +48,6 @@ public Canvas(Skin.Base skin, string? name = default) : base(parent: null, name:
4848 ShouldDrawBackground = false ;
4949 IsTabable = false ;
5050 MouseInputEnabled = false ;
51-
52- mDisposeQueue = new List < IDisposable > ( ) ;
5351 }
5452
5553 /// <summary>
@@ -241,29 +239,45 @@ private void DoThink()
241239 /// <param name="control">Control to delete.</param>
242240 public void AddDelayedDelete ( Base control )
243241 {
244- if ( ! mDisposeQueue . Contains ( control ) )
242+ lock ( _disposeQueue )
245243 {
246- mDisposeQueue . Add ( control ) ;
247- control . Parent ? . RemoveChild ( control , false ) ;
248- }
244+ if ( ! _disposeQueue . Contains ( control ) )
245+ {
246+ _disposeQueue . Add ( control ) ;
247+ control . Parent ? . RemoveChild ( control , false ) ;
249248#if DEBUG
250- else
251- {
252- throw new InvalidOperationException ( "Control deleted twice" ) ;
253- }
249+ _delayedDeleteStackTraces . Add ( control , new StackTrace ( ) ) ;
250+ }
251+ else
252+ {
253+ throw new InvalidOperationException ( "Control deleted twice" ) ;
254254#endif
255+ }
256+ }
255257 }
256258
259+ #if DEBUG
260+ private readonly Dictionary < Base , StackTrace > _delayedDeleteStackTraces = [ ] ;
261+ #endif
262+
257263 private void ProcessDelayedDeletes ( )
258264 {
259- //if (m_DisposeQueue.Count > 0)
260- // System.Diagnostics.//debug.print("Canvas.ProcessDelayedDeletes: {0} items", m_DisposeQueue.Count);
261- foreach ( var control in mDisposeQueue )
265+ lock ( _disposeQueue )
262266 {
263- control . Dispose ( ) ;
264- }
267+ foreach ( var control in _disposeQueue )
268+ {
269+ #if DEBUG
270+ if ( control is Base node )
271+ {
272+ _delayedDeleteStackTraces . Remove ( node ) ;
273+ }
274+ #endif
265275
266- mDisposeQueue . Clear ( ) ;
276+ control . Dispose ( ) ;
277+ }
278+
279+ _disposeQueue . Clear ( ) ;
280+ }
267281 }
268282
269283 /// <summary>
0 commit comments