App crashed when starting : Event loop

I developed an App for MacOS and Windows, and I want to build an update.

On MacOS, no trouble, everything is working well.

With the last XOJO relase 2025r2.1, I tested my App on Windows and it crashes while starting.

The debugger shows the following error:

Your application crashed due to an access violation. The Debugger may show invalid values. Check the selected line, make corrections, and try again.

> Stack - Main Thread
> Event Loop

I have no more details. What can I do?

Try launching the debug session using the “Run Paused” option. That may let you get into the debugger before whatever is causing this issue.

1 Like

Thanks, I finally found the origin of the problem : a function closed its window before returning a value, and it seems to crash the program.

If you can take a minute and create a small project that crashes like this, the Xojo team would surely appreciate it. You shouldn’t be able to crash like this using conventional Xojo code.

Unless he’s returning a property of a control that belongs to the closed window.

I tried to reproduce this issue with a new project, but closing before returning a value doesn’t seem to crash the app.

It’s probably the combination with other factors that causes the crash.

It seems my issue is not fully resolved, unfortunately…

In fact, when my App is starting, I’m detecting if there is any News to display :

dim w As new wNews
var newsFound As Boolean =  w.readXml(progInit)
w.Close
return newsFound

Here is the readXml function:

self.hide()

me.progInit = progInit

Dim file As FolderItem

#if TargetMachO
  file = sandBoxFolder.Child("mcnews.xml")
#elseif  TargetWin32
  file  =SpecialFolder.Preferences.child("MacCompta").child("mcnews.xml")
#endif


if (file = nil) then
  'close()
  return False
  
else

  dim url As String
  dim os As String
  dim systemVersion As String
  #if TargetMacOS then
    os = "Mac OS X"
  #elseif TargetWin32 then
    os = "Windows"
  #endif
  systemVersion = getSystemVersion()
  
  url = "https://www.mywebsite.ch/news/checknews.php?app="+str(app.majorVersion)+"."+str(app.minorVersion)+"."+str(app.bugVersion)+"&os="+os+"&v="+systemVersion+"&licence="+str(IDForSN(serialNumber))+"&lang="+kLanguageIdentifier+"&output="
  url = ReplaceAll(url," ","%20")
  
  if (System.Network.LookupIPAddress("mywebsite.ch")<>"" and socketUpdater.get(url+"xml",file, 5) and file.length>60) then
    
    Dim xml As new XmlDocument
    Dim nodeCurrentNews As XmlNode
    Dim currentNewsID As Integer
    Dim forceNews As Boolean = false
    
    if(file = nil or not file.Exists) then
      dim c As new Clipboard
      c.Text = url
      return false
    end if
    
    try
      xml.loadXml(file)
      xml.PreserveWhitespace = False
      
      nodeCurrentNews = xml.DocumentElement.FirstChild
      currentNewsID = val(nodeCurrentNews.Child(0).FirstChild.Value)
      forceNews = (val(nodeCurrentNews.Child(1).FirstChild.Value)=1)
      
    Catch e As XmlException
         return false
    end try
    
    if(showNews(currentNewsID, forceNews)) then
      dim s As new HTTPSocket
      dim sourceCode As String = DefineEncoding(replaceAll(s.Get(url+"html",90),chr(13),endOfLine), Encodings.UTF8)
      Dim f As FolderItem = GetTemporaryFolderItem
      HTMLInfos.LoadPage(sourceCode, f)
     
      return true
      
    else
      'close()
      return False
    end if
    
  elseif(not progInit) then
    'close()
    return False
  else
    'close()
    return False
  end if
end if


I finally found that the App crashed when w.Close is called. If I comment this line, everything works properly, and I don’t understand why.

I checked the wNews window and the closing event is not used.

Any idea? Thanks for your help.

A simple trick to avoid such situations is not to do too much in App.Open. Instead use a single timer call and do your initialisations there.

Thanks for your replies. I tried to use a timer in my wNews that closes the window after X seconds, it seems to work now.

Why is that code even in a window? It doesn’t appear to interact with the UI at all.

1 Like

Even then, the framework should throw some kind of exception.

Sure, it’s not the best way I guess, but when a news item exists, the wNews window is shown and displays it.