Crash - perhaps on TitleChange for HTMLviewer?

Hi -

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.

Any help appreciated!

Hamish

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 com.apple.WebCore 0x91548779 WebCore::Page::remoteInspectorInformationDidChange() const + 9 1 com.apple.WebCore 0x90adf117 WebCore::FrameLoader::didChangeTitle(WebCore::DocumentLoader*) + 199 2 com.apple.WebCore 0x90adf014 WebCore::DocumentLoader::setTitle(WebCore::StringWithDirection const&) + 148 3 com.apple.WebCore 0x90acf325 WebCore::Document::updateTitle(WebCore::StringWithDirection const&) + 1013 4 com.apple.WebCore 0x91040a3f WebCore::HTMLTitleElement::childrenChanged(WebCore::ContainerNode::ChildChange const&) + 143 5 com.apple.WebCore 0x90a493dd WebCore::ContainerNode::parserAppendChild(WTF::PassRefPtr<WebCore::Node>) + 381 6 com.apple.WebCore 0x90aca2ec WebCore::HTMLConstructionSite::insertTextNode(WTF::String const&, WebCore::WhitespaceMode) + 1756 7 com.apple.WebCore 0x90ac9b8b WebCore::HTMLTreeBuilder::processCharacterBuffer(WebCore::HTMLTreeBuilder::ExternalCharacterTokenBuffer&) + 2251 8 com.apple.WebCore 0x90a46e36 WebCore::HTMLTreeBuilder::processToken(WebCore::AtomicHTMLToken*) + 278 9 com.apple.WebCore 0x90a46c64 WebCore::HTMLTreeBuilder::constructTree(WebCore::AtomicHTMLToken*) + 228 10 com.apple.WebCore 0x90a46871 WebCore::HTMLDocumentParser::constructTreeFromHTMLToken(WebCore::HTMLToken&) + 161 11 com.apple.WebCore 0x90a33c9f WebCore::HTMLDocumentParser::pumpTokenizer(WebCore::HTMLDocumentParser::SynchronousMode) + 463 12 com.apple.WebCore 0x90ac629f WebCore::HTMLDocumentParser::append(WTF::PassRefPtr<WTF::StringImpl>) + 463 13 com.apple.WebCore 0x90e90702 WebCore::DecodedDataDocumentParser::appendBytes(WebCore::DocumentWriter&, char const*, unsigned long) + 114 14 com.apple.WebCore 0x90ab4a64 WebCore::DocumentWriter::addData(char const*, unsigned long) + 52 15 com.apple.WebCore 0x90a26ee7 WebCore::DocumentLoader::commitData(char const*, unsigned long) + 567 16 com.apple.WebKitLegacy 0x9aa0be7c -[WebFrame(WebInternal) _commitData:] + 124 17 com.apple.WebKitLegacy 0x9aa0bcae -[WebHTMLRepresentation receivedData:withDataSource:] + 94 18 com.apple.WebKitLegacy 0x9aa0bbed -[WebDataSource(WebInternal) _receivedData:] + 77 19 com.apple.WebKitLegacy 0x9aa0bb78 WebFrameLoaderClient::committedLoad(WebCore::DocumentLoader*, char const*, int) + 120

Post your code from the TitleChanged event…

[quote]
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&"  _
+ "client_secret=MYCLIENTSECRET&redirect_uri=MYREDIRECTURI&grant_type=authorization_code"
mySocket.Secure = True
mysocket.SetRequestHeader("Host", "accounts.google.com")
mySocket.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
mysocket.SetPostContent(s, "application/x-www-form-urlencoded" )
mySocket.SetRequestHeader("Content-Length", cStr(Lenb(s)))
s = mySocket.post("https://accounts.google.com/o/oauth2/token", 0)

try
  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
    mysocket.SetRequestHeader("Host", "accounts.google.com")
    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.
      
      
    end
  end
catch err as JSONException
  Call fileFunctions.writeLogFile( "JSON exception while reading string. String: " + s  )
end

callingWindow.myDetailPanel.dpReloadRecord

Me.Window.Close

end[/quote]

The crash happens after the final ‘end’.

Not sure that this is helpful…

Might be due to the thread being called during the event…

I don’t think so, because the crash report is talking about stuff happening in WebCore::Page::remoteInspectorInformationDidChange, which is nothing to do with the thread that’s being called.

…but for the avoidance of doubt, I commented that bit out, and it’s still crashing.

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…

Or wait until DocumentComplete is over ?

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.