I embed some container controls in a window, a slider in the container control executes a method which may need to close this container control and recreate it.
To avoid calling a containercontrol.close from a method called from the containercontrol itself (which causes a crash) I do it with a timer set to 1 second after slider changes but sometimes it still crashes which means it is not safe to close the container control.
Is there a way to know if it is safe to close and remove it?
Application Specific Information:
abort() called
TeamPhotoComposite.debug(2542,0x105186e00) malloc: Heap corruption detected, free list is damaged at 0x600001f2d0e0
*** Incorrect guard value: 281479271677951
This is deep into the bowels of macOS. Your Xojo version is really old. I will assume that you have reasons for using such an old version. But first thing I’d try is with 2020r2.1.
Doing this by a timer is good. But it sounds that the code that the timer action event executes lives in the container. Move it to the window an store a reference somewhere to access the container. This should not crash.
Thanks, it is actually in the main window and I have set it to different times like 1 1.5 and 2 seconds. For some reason it still crashes sometimes but not always.
The code to close the containercontrols is called by the Timer in the main window.:
for n as integer = 0 to aMyCC.Ubound
aMyCC(n).Close
next n
Redim aMyCC(-1)
Make sure that no control of a closing container has the focus. I would overwrite the container Close method to ensure that all timers, threads and other depencies are closed/removed before calling super.Close.
Thanks, I thought about this but I expected to be nil once closed, actually I can close a single ContainerControl from the array and the array doesn’t changes (Containercontrol handle is 0 but top value and others are still there) until I remove it.
Yes, it’s the same behaviour as with windows; you have to check the handle.
And do it the way DerkJ wrote: Iterate the array from the last item to the first. So you can safe remove the array item directly after closing the container.