Xojo desktop app crashes

Using Xojo 2018 r2 on MacOS 10.13.4 to compile (64-bit). IDE runs fine - no issues.

The compiled 64-bit desktop app crashes frequently using MacOS 10.11.6. When running the debug version, I can consistently make it crash when I close a certain window. The IDE is brought up but no code is noted in the window as to where the crash occurred. If I hit the “run” arrow, I get a Nil object exception.

Usually a crash highlights the offending error. How do you figure out this sort of error?

Sigh… your description is very vague. A crash is not an exception.

Where do you get the NOE? Is there something nil?

No line of code is error highlighted. Stack information in the app.UnhandledException reads:

[code]NilObjectException

RuntimeRaiseException
RaiseNilObjectException
Delegate.IM_Invoke%%o
AddHandler.Stub.17%%
_ZN17RuntimeEditRouter20EditControlLostFocusEP11EditControl
_Z12SetFocusPaneP7SubPane
_ZN7SubPane8SetFocusEv
_ZN17RuntimeViewWindow8ActivateEv
XojoFramework$5272
CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER
_CFXRegistrationPost
___CFXNotificationPost_block_invoke
-[_CFXNotificationRegistrar find:object:observer:enumerator:]
_CFXNotificationPost
-[NSNotificationCenter postNotificationName:object:userInfo:]
-[NSWindow becomeKeyWindow]
-[NSWindow _changeKeyAndMainLimitedOK:]
-[NSWindow _orderOutAndCalcKeyWithCounter:stillVisible:docWindow:]
NSPerformVisuallyAtomicChange
-[NSWindow _doWindowOrderOutWithWithKeyCalc:forCounter:orderingDone:docWindow:]
-[NSWindow _reallyDoOrderWindowOutRelativeTo:findKey:forCounter:force:isModal:]
-[NSWindow _reallyDoOrderWindow:relativeTo:findKey:forCounter:force:isModal:]
-[NSWindow _doOrderWindow:relativeTo:findKey:forCounter:force:isModal:]
-[NSWindow orderWindow:relativeTo:]
-[NSWindow _finishClosingWindow]
-[NSWindow _close]
_ZN14WindowImpCocoa10HideWindowEv
_ZN6Window5CloseEv
_ZN11RuntimeView12UnifiedCloseEb
XojoFramework$5274
__19-[NSWindow __close]_block_invoke
-[NSWindow __close]
-[NSApplication(NSResponder) sendAction:to:from:]
-[NSControl sendAction:to:]
__26-[NSCell _sendActionFrom:]_block_invoke
-[NSCell _sendActionFrom:]
-[NSButtonCell _sendActionFrom:]
-[NSCell trackMouse:inRect:ofView:untilMouseUp:]
-[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:]
-[NSControl mouseDown:]
-[_NSThemeWidget mouseDown:]
-[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:]
-[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:]
-[NSWindow(NSEventRouting) sendEvent:]
XojoFramework$4966
-[NSApplication(NSEvent) sendEvent:]
XojoFramework$4511
Application._CallFunctionWithExceptionHandling%%op
_Z33CallFunctionWithExceptionHandlingPFvvE
XojoFramework$4511
-[NSApplication run]
RuntimeRun
REALbasic._RuntimeRun
_Main
main[/code]

Hmmm… I notice that if I am not in the “myTextField” the error does not occur. At least that’s a start.

After downgrading to Xojo 2017 r3, the crashing seems to have stopped. Not sure exactly, but the problem appears to be related to textfield lostfocus event firing after the window closes and the object is now nil.

So what exact code is in your lostfocus event?

I have a textfield subclass that I created called mytextfield which has different methods to format the current textfield.

[code]
//lostfocus event in mytextfield fldDate
me.Text = FormatDate(me.Text)
fldPaid.SetFocus

EnableSave[/code]

[code]
//EnableSave method - enables the bOK button so you can save the data

bOK.Enabled = False

If (fldDate.Text = “”) Or (fldDate.Text = “01/01/1901”) then
fldDate.SetFocus
Return
End if

If (Listbox3.ListCount > 0) then //there must be an invoice in the ApptTo listbox

If (Label_PmtType.Text = “Payment”) And (PagePanel3.Value=0) then //It’s a payment
If (CDbl(fldPaid.Text) > 0) Then //the amount paid must be greater than zero
If pb_EOB.Visible = False then
bOK.Enabled = true
End If
End if
Else //It’s an adjustment
If pb_EOB.Visible = False then
bOK.Enabled = true
End If
End if

End if

If (rb_ToPt.Value = False) then
Dim vBal as Currency = 0
Dim i as Integer
For i = 0 to 4
vBal = vBal+CDbl(vBalanceAmt(i).Text)
Next
vbal = Val(Format(vBal,"#######0.00;-########0.00;0.00"))
If Not (vBal=CDbl(vbalance.Text)) then
bOK.Enabled = false
End if

If (PagePanel3.Value = 1) then 'you are entering line level payments
If pb_EOB.Visible = False then
bOK.Enabled = true
End If
End if
End if[/code]

[quote]fldPaid.SetFocus
bOK.Enabled = False
fldDate.SetFocus[/quote]

These will all fail with a nil object exception if those objects have been destroyed before the lost focus code is called.

Try adding a property ‘windowclosing’ as boolean to the window
Set it to true when the close event is called

Then in your lostfocus event,

if windowclosing then exit sub

Or add an exception handler to the lostfocus event
Even just putting the word Exception as the last line before exit Sub would probably deal with the problem.

Thanks for your help.

Did something change? My downgraded app using Xojo 2017 r3 was put into production today with most all errors eliminated.

I am also finding other changes in behavior in Xojo 2018 vs 2017 - such as when opening a window, the method places the cursor in one field (the desired field) in 2017 and a different field (the undesired field) in 2018. I can’t say for sure, but it seems that event methods for windows and fields seem to fire differently (in a different order maybe?) in version 2018.

Could be.
Wouldnt be the frist time
It doesnt pay to assume the order is fixed.
Didnt the creation order change in order to try to reduce flickering?

[quote=410054:@Jeff Tullin]Try adding a property ‘windowclosing’ as boolean to the window
Set it to true when the close event is called

Then in your lostfocus event,

if windowclosing then exit sub[/quote]

Worked perfectly - thanks.