Web Canvas paint event keeps running after closing

Hi,

I’m not sure I identified correctly the problem but here is what is happening :

1- A window in opened and it loads data from the database that is used to populate container controls created on the fly.
2- Each of the created Container Controls contain various controls among wihich a Canvas Class (to show pictures) with a Webpictures array property that stores the pictures. The pictures used to populate the canvas are downsized versions of the original picture. Their weight is around 100 ko each.
3- The way code is built, each container control should be created one after the other. Data and pictures are added at creation.
4- In reality, container controls will show with data but pictures are loaded progressively after all controls have already shown. It is, of course, especially obvious when many containers are created. It may take over 1 minute to load all pictures ( test scenario of 30 containers with 2 pictures each )
5- I can live with the delay but the problem occurs when the main window is closed before all canvas paint event has executed successfully. I get nil exception errors for the canvasses that are still loading pictures.

I’ve tried closing each container object, setting classes or the whole window to Nil but that did not work. I’ve also created the containers as WeakRefs but I’m not sure I used them properly.

How can I handle such situations?

Maybe that could help …

Error code :

Could not execute returned javascript: this.object(...) is null Source: try { Xojo.controls['EuTJUIu9'].editScript(1,'context.clearRect(0,0,240,179);',23); Xojo.controls['EuTJUIu9'].runScript(2); } catch(ex) { } new imageview('iLvsVM5s',[]); Xojo.controls['iLvsVM5s'].setEnabled(true); Xojo.controls['iLvsVM5s'].shouldBecomeVisible = false; Xojo.controls['iLvsVM5s'].setSize(720,960); Xojo.input.install(Xojo.controls['iLvsVM5s'].object()); Xojo.controls['iLvsVM5s'].setSource("/61AFC46AA2016121CFB23FE0DAA1D4D100D98189/files/5179-1179-0574-3589-1054/picture.png"); Xojo.controls['iLvsVM5s'].setSize(null,null); Xojo.controls['iLvsVM5s'].setVisible(false); Xojo.controls['iLvsVM5s'].refresh(); Xojo.controls['aK7Tc4tN'].setValue("1");

Or set a terminating flag when the window is closed and check that at each step in the canvas paint event.

Hi Tim, I’ll try that.

I’ve Created a Session Boolean property (“stopLoading”) that is set to True when I close the window. It seems that it keeps being set to False since the code keeps executing.

Should I create it elsewhere?

The close event of my window was triggered after the execution of the code. Changing the value of the “stopLoading” property on the push of a button solved the problem.

Thank you very much!

We usually have a cancel flag on the thread.
So if user cancels or window closes, we set cancel = true.

in the thread, we check on various places for the flag and just return there to quit.
This is much better than Kill method.

Hi Christian,
All the process was actually in a thread before I put it back into the main code. I took that decision after reading that thread code should not have “intercations” with the interface. I thought at first that it could be the source of the crash but it wasn’t. I’ll leave the code as it is and might pout that back in separate threads.

Thanks for the tip!