Debugger crashes

Hi

I’m writing a program. And the debugger crashes. So I run my code, everything works. I press a button which triggers some code. And OSX throws an ‘Program stopped responding’ or something like that.

Also, it happens only when I trigger that button with the code inside, no other buttons. The code inside that button created some XML.

What could be the reason of this behaviour?

A 1001 different things. If you want help, you’re going to have to provide more details. Why not start with the code inside that button that courses the crash. Also, if you get an error msg. write down exactly what it says.

Fair enough!

First of all, no Message appears, normally I would expect a nilobject or out of bounds exception or something similar. Now nothing, just a plain crash, the stacktrace of Xojo shows nothing.

I’m going to explain the code as much as I can.
The code that is called on the button is: (It’s just a testbutton)

msgbox(LocalSystem.AssetLibrary.ToXML.ToString)

Where LocalSystem is a Module, AssetLibrary is a property of the class ‘AssetFolder’ on that module.

The ToXML method on the AssetFolder class looks like this:

[code]Public Function ToXML() as XmlNode
Dim xml As XmlNode = Super.ToXML

For Each a As Asset In GetAssetsAndFolders
xml.AppendChild(a.ToXML)
Next

Return xml
End Function
[/code]

AssetFolder is a subclass of ‘Asset’, So Super.ToXML is this method:

[code]Public Function ToXML() as XmlNode
Dim xml As New XmlNode
Dim className As String = Introspection.GetType(Me).Name

xml.Name = className.Lowercase
xml.SetAttribute(“id”, ID)
xml.SetAttribute(“icon”, IconID)

Return xml
End Function
[/code]

What I expect to get is:

An XmlNode created by the superclass Asset, The AssetFolder.toXML should append child Assets and Folders in the GetAssetsAndFolders array. Then It should return that XmlNode and show it in a msgbox via the ToString method.

Is my logic flawed? Moreover, why doesn’t the Xojo debugger show me what is wrong, it’s just plain quitting without information. Never seen that at all.

Thanks! If you have any more questions regarding the code, just ask!

I have a gut feeling it has something to do with instantiating the XMLNode class, but I have no idea what would be wrong with that.

I did some breakpoint testing.
The line that failes is this one:

xml.Name = className.Lowercase

If I put a breakpoint on that line, the code just runs and stack trace shows everything, press ‘Run’ again and debugger crashes.

I have no clue what’s wrong here.

EDIT: It’s getting weirder and weirder. I put a break on that line, checking the variables, everything ok. The moment I try to inspect the xml variable, the debugger crashes. Something is really wrong with the XmlNode class apperently.

I made a little sample project:

Create a new project → add a button → action event:

[code] Dim xml As New XmlNode

	xml.Name = "Test"[/code]

Click the button, debugger crashes.

Feedback case: <https://xojo.com/issue/46850>

Yeah there are 2 issues here

  1. you need to use the factory methods on XML document (see the examples on http://documentation.xojo.com/index.php/XMLNode)
  2. the classes you’re trying to use “new” with should have protected constructors so that you’re code doesn’t compile (it really shouldn’t)

Aha ok, will use the factory methods. But documentation is not very clear.

“Usually” and “Most” implies that it should be possible to instantiate directly, altough not very common.

Is there a reason why it shouldn’t be possible to instantiate those classes directly? Not a huge problem, but now I have to create an extra object (XmlDocument) on every method that spits out a XmlNode.

[quote=313524:@Mathias Maes]Aha ok, will use the factory methods. But documentation is not very clear.
[/quote]
Agreed

Its just how things work in that plugin