I’ve got an HTMLviewer in a dialog in a desktop application, and I do a bunch of stuff in the TitleChanged event, which includes things like closing the window which it’s in.
It all worked fine in RealStudio, but since updating to Xojo, I’m getting a crash when the TitleChanged subroutine finishes (i.e. after End Sub, if I’m in the debugger.
Can anyone make any suggestions as to what I should be doing to prevent this? I’ve tried to reproduce it in a sample project but I’m having some difficulty with the code not loading stuff into the HTMLviewer; thought I would ask here first before spending yonks trying to reproduce it.
if left(newTitle, 13)=“Success Code=” then
successCode = right(newTitle, len(newTitle)-13)
changeLabel “Getting authorization code…”
dim mySocket as HTTPSecureSocket = new HTTPSecureSocket
dim s as string = "code=" + successCode + "&client_id=MYCLIENTID&" _
mySocket.Secure = True
mysocket.SetPostContent(s, "application/x-www-form-urlencoded" )
s = mySocket.post("https://accounts.google.com/o/oauth2/token", 0)
dim j as new JSONItem(s)
if j.HasName("refresh_token") then
// Stuff is saved to the database here, which I've taken out for the purposes of this forum post.
changeLabel "Getting user details..."
mySocket = new HTTPSecureSocket
mySocket.Secure = True
s = mySocket.get("https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + j.Value("access_token"), 0)
j = new JSONItem(s)
if j.HasName("email") then
// More database saving stuff
// run a thread here to publish to Google Calendar.
catch err as JSONException
Call fileFunctions.writeLogFile( "JSON exception while reading string. String: " + s )
So, it seems that calling Me.Window.Close from within HTMLViewer.TitleChanged is giving this crash, but I can’t test it because I can’t seem to get LoadURL working (grr).
I 've worked around this by making a timer on the parent window, setting its mode to Off and its action to close the window. At the end of my title changed method, I’m now setting the timer’s mode to ModeSingle, with a period of 10ms, which then closes the window: no crash.
[quote=177999:@Hamish Symington]So, it seems that calling Me.Window.Close from within HTMLViewer.TitleChanged is giving this crash, but I can’t test it because I can’t seem to get LoadURL working (grr).
I 've worked around this by making a timer on the parent window, setting its mode to Off and its action to close the window. At the end of my title changed method, I’m now setting the timer’s mode to ModeSingle, with a period of 10ms, which then closes the window: no crash.[/quote]
I used the same trick not long ago in may latest app, after pulling my remaining hair over a similar unexplained crash. Worse, it affected a window that worked perfectly well in the separate project I had created it in, but once pasted into the big project, kaboom. There again, a 17 ms timer just solved the issue. I will probably never know what was really going on, but sometimes sweeping things under the carpet is the only way not to loose it.
The one thing I noticed with the HTMLViewer on Cocoa is it will run code before returning, so you are asking the window to close, but the control is not done with the event… Perhaps you could make the TitleChanged event call me.Close and in the Close event try to close the parent window…
A bit of digging on DocumentComplete says that it might fire several times during a web page load (depending on redirects etc) which isn’t great. I did try making the titleChanged event call Me.Close, but it’s the closing of the HTMLViewer that’s causing the problem in the first place! The timer’s working well, even if it’s a bit of a fudge.
Actually, I thought about a combination of both timer and DocumentComplete. In DocumentComplete, you start a Timer, which keeps pushing it back, until the last DocumentComplete arrives, and lets the timer Action occur.