Very weird behaviour of the IDE (array is changing between steps)

This is rather odd and I don’t yet know how to debug it.

In a method, I have this line:

SelectObjects UndoNext.Value("Selection"),True //UndoNext is a dictionary

The SelectObjects method looks like this:

Sub SelectObjects(Objects() As Object2D,Only As Boolean)
if Only then DeselectAll //A method which deselects the currently selected items

for each o2d as Object2D in Objects
AddObjectToSelection o2d
End Sub

By putting a breakpoint at the “for each” line, the debugger tells me “Objects” contains 3 items, which is as expected. Then, I hit “Step over” and “Objects” changes to an empty array. If this was earlier (e.g. at the “DeselectAll” statement), I’d conclude the DeselectAll method can be the culprit, but no, it happens after the “for” statement.

If I check the content of “Objects” in the IDE, even before the first line of SelectObjects is executed, my app crashes (EXC_BAD_ACCESS).

I’m writing this post because of the crash and the fact that the variable changing at a “for” statement doesn’t sound logical to me.
Or perhaps I’m missing something?

Does addobjecttoselection modify the array?

You can try adding a pragma

#Pragma BackgroundTasks false

Above the loop?

Worse… Circular reference, I’m afraid…
The passed parameter is actually the selection (which, of course, gets removed because of the “DeselectAll” call).
I actually searched for another cause, because of Xojo’s behaviour of changing the parameter “too late” (after the “for” statement). But I tried again this morning and the behaviour changed as it should have been (now, the parameter is changing at the expected line, after DeselectAll), so it’s indeed just the simple circular reference at play.
I’ll have to redesign my app to include some kind of “unique reference number” to refer to items by identifiers rather than references… oh well…

Thank you.

1 Like