I have an app that in one circumstance (other than crashing) fails to call the App. Close event when shutting down. Here is the matrix:
Close via File:Quit menu (32-bit) - OK
Close via window’s close button (32-bit) - OK
Close via File:Quit menu (64-bit) - OK
Close via window’s close button (64-bit) - FAIL
Now, in the App.Open event I have
App.AutoQuit = True
as the first line. At the end of the main window’s Close event I have the following cleanup code
[code]// clean up any open windows
For i As Integer = WindowCount - 1 DownTo 0
If Window(i) <> Nil Then Window(i).Close
Next
// Quit
Quit[/code]
I do not have App.CancelClose implemented. When the window closes, the only thing left open is the database connection but the database (SQLite) is global and the connection was created in the App level methods.
What is driving me crazy about this is that it is only a problem when I compile for 64-bit. The exact same code built for 32-bit works fine.
I am working on a 64-bit Windows 10 system with Xojo 2017r2.1.
what I use is “slightly” different. but is in APP.CLOSE not mainWindow.close
For i As Integer = WindowCount - 1 DownTo 0
Dim w As Window = Window(i)
If (w <> Nil) Then
w.Close
End If
Next
I think the problem with it in the MainWindow, is that loop also refers to “MainWindow”, but you don’t know in what order, so it might conflict with itself.
@Markus Winter: 64bit seems to do slightly different things when closing compared to 32bit. This Feedback issue makes debugging for me totally annoying: <https://xojo.com/issue/48395>. Unfortunately, I’m the only one to have this issue.
[quote=356648:@Dale Arends]Close via File:Quit menu (32-bit) - OK
Close via window’s close button (32-bit) - OK
Close via File:Quit menu (64-bit) - OK
Close via window’s close button (64-bit) - FAIL
[/quote]
[quote=356652:@Dave S]what I use is “slightly” different. but is in APP.CLOSE not mainWindow.close
For i As Integer = WindowCount - 1 DownTo 0
Dim w As Window = Window(i)
If (w <> Nil) Then
w.Close
End If
Next
I think the problem with it in the MainWindow, is that loop also refers to “MainWindow”, but you don’t know in what order, so it might conflict with itself.[/quote]
Dave, I tried your suggestion but it didn’t help. I still saw the same problem.
Michel, I would except that I’m not convinced that it is a bug in Xojo or a bug in my code/design. Unfortunately, I can’t submit the project as an attachment due to a non-disclosure agreement and I haven’t been able to reproduce it with a test project.
Markus, you’re probably correct but I come from the “old school” of programming that taught us to close anything you open, just in case, since back then the environment didn’t clean up things. That meant that if you forgot to close windows or nil out structures, etc., you would wind up with massive memory leaks. Old habits, I guess.
Michel, I’m going to take your response as a genuine request and not a snide comment. Yes, apparently it IS difficult since whenever I create the test program it did not manifest the problem. As I stated, I have not been able to reproduce it with a test program. It’s not that I can’t create a test program but, rather, the test program does not show the problem. If you, or anyone else for that matter, is successful in doing so, please do submit it in a bug report.
Hi Dale. I assume you’ve tested putting in some debug logging when you open a window and when you close them to make sure that you have the same number of opens and closes at the end of your program?
[quote=356868:@JulianS]Hi Dale. I assume you’ve tested putting in some debug logging when you open a window and when you close them to make sure that you have the same number of opens and closes at the end of your program?
Also, are you using any declares in your project?[/quote]
Julian, no I don’t track the opens and closures of windows since I have the code check for and close any open windows before closing the main window. Also no. this particular program does not use any declares nor 3rd party plugins.
Markus, the only window with implicit instantiation is the main window. All others have implicit instantiation off.
By the way, before I forget, I want to thank everyone who has made suggestions. You folks are awesome.
Ok, let’s add to the confusion. The last statement in the main window’s Close event handler was
// Quit
Quit
Just for a test, I removed that and the App.Close event was called properly. Yet, in my test apps if I have that statement present, I still couldn’t get the test apps to manifest the problem. So I don’t know if having a Quit statement at the end of the window’s Close event handler is good or bad in general. For now, I’m leaving it out. (And heading for the Scotch bottle.)
[quote]Ok, let’s add to the confusion. The last statement in the main window’s Close event handler was
// Quit
Quit[/quote]
This triggers a memory: I recall having had to remove “quit” from a close.event in order to have the app quit.
That happened a few months ago when I started debugging my apps in 64bit with Xojo 2017 2.1
macOS 10.12.6
Yes, Markus, both the “real” app and the test app(s) had AutoQuit on. I have no real explanation for what caused the problem but, for now at least, I’m taking the Quit statement out of the window’s Close event.