CloseQuery and TCastleView?

I am unable to figure out how to trap the closing of the program so I can stop the water work threads. My app is based on wyrdforest so it is a TCastleView, not a TCastleWindow. So doesn’t seem to have the CloseQuery callback. The stop method in my TViewPlay never gets called when you press the close X on the window. The threads keep running since they are stopped from stop method. The program then never closes without being terminated from ide.

I think I have it working correctly now, I am not sure what I did differently.

To be clear, our wyrd-forest ( GitHub - castle-engine/wyrd-forest: Game about walking in a weird forest, planting healing trees, and shooting evil targets. Game sponsored by Patreon supporters, showing off various Castle Game Engine features. ) is a rather regular Castle Game Engine application (at this moment, it was a bit non-standard ~2 years ago, but I refactored it since then) and it uses TCastleWindow. It also uses TCastleView to organize work within the window – this is again completely normal, and fully recommended approach.

Most “normal” CGE applications should use TCastleWindow (only those that have a good reason can consider using alternative TCastleControl, Engine on a form (VCL, FMX, LCL) using TCastleControl | Manual | Castle Game Engine ). And all bigger CGE applications (whether using TCastleWindow or TCastleControl) are recommended to organize their work into TCastleView. So you’re in good company, you have things completely standard :slight_smile:

The virtual Stop of your view should always be called – if it doesn’t please report a bug :slight_smile: Even when you just close the application by Alt + F4 (X on toolbar), at the end we finalize everything, this includes stopping the current view. I just tested to confirm it is true, did minimal modifications to the new project from “Empty” template as shown below, it goes OK – running and closing shows “Stop called!”.