Setting a boolean value makes a hard crash

I’ve just gotten very strange crash logs from a customer:

0 com.mothsoftware.mailarchiverx 0x011e0b96 EmailInfo.isActive.Set%%oi4b + 84
1 com.mothsoftware.mailarchiverx 0x00a62958 CCAccountAndMailbox.CCAccountAndMailbox.MailApplicationActiveChanged%%o<CCAccountAndMailbox.CCAccountAndMailbox>sb + 422
2 com.mothsoftware.mailarchiverx 0x00dc4a54 SetupWindow.SetupWindow.CCEmailApp1_EmailClientActiveChanged%%o<SetupWindow.SetupWindow>o<CCEmailApp.CCEmailApp>sb + 240
3 com.mothsoftware.mailarchiverx 0x00dd22fb Delegate.IM_Invoke%%o<CCEmailApp.CCEmailApp>sb + 110
4 com.mothsoftware.mailarchiverx 0x00dd23b9 AddHandler.Stub.40%%sb + 83
5 com.mothsoftware.mailarchiverx 0x00aaf031 CCEmailApp.CCEmailApp.LBMailClients_CellAction%%o<CCEmailApp.CCEmailApp>oi4i4 + 1343
6 com.mothsoftware.mailarchiverx 0x00accd41 Delegate.IM_Invoke%%oi4i4 + 103
7 com.mothsoftware.mailarchiverx 0x00accd97 AddHandler.Stub.41%%i4i4 + 74
8 com.mothsoftware.mailarchiverx 0x009fa6cf UndoableListbox.Event_CellAction%%oi4i4 + 1254

EmailInfo is a helper class for containing and manipulating some Json. isActive is a computed property:

isActive As Boolean Get return misActive exception exc theException = new ErrorException(exc, currentMethodName) End Get Set misActive = value exception exc theException = new ErrorException(exc, currentMethodName) End Set

This code crashed for the customer 4 times. Does anyone have an idea what could cause the crash? I don’t remember why the property is computed. I could exchange this for a normal property, of course.

2015r4, Mac OS 10.11.3.

Access on self for a released object maybe.
So reference counting could be wrong.
But you would need to use a plugin for that or overwrite memory.

Difficult to say, because:

Incomplete crash log. Might be another thread that crashed. The posted part doesn’t say what kind of crash it is.

There is no code in your post (meaning the code which leads to the use of isActive).

Here is the complete crash log:

Process: Mail Archiver X [80158]
Path: /Applications/Mail Archiver X/Mail Archiver X.app/Contents/MacOS/Mail Archiver X
Identifier: com.mothsoftware.mailarchiverx
Version: 4.0.0 20160312
(4.0.0.3.1121)
Code Type: X86 (Native)
Parent Process: ??? [1]
Responsible: Mail Archiver X [80158]
User ID: 501

Date/Time: 2016-03-13 07:24:22.324 -0700
OS Version: Mac OS X 10.11.3 (15D21)
Report Version: 11
Anonymous UUID: CA763AC8-2650-DD5D-A43B-144EA95AF882

Time Awake Since Boot: 680000 seconds

System Integrity Protection: enabled

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000ffffffef
Exception Note: EXC_CORPSE_NOTIFY

VM Regions Near 0xffffffef:
–> shared memory 00000000ffffd000-00000000ffffe000 [ 4K] r-x/r-x SM=SHM

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 com.mothsoftware.mailarchiverx 0x011e0b96 EmailInfo.isActive.Set%%oi4b + 84
1 com.mothsoftware.mailarchiverx 0x00a62958 CCAccountAndMailbox.CCAccountAndMailbox.MailApplicationActiveChanged%%o<CCAccountAndMailbox.CCAccountAndMailbox>sb + 422
2 com.mothsoftware.mailarchiverx 0x00dc4a54 SetupWindow.SetupWindow.CCEmailApp1_EmailClientActiveChanged%%o<SetupWindow.SetupWindow>o<CCEmailApp.CCEmailApp>sb + 240
3 com.mothsoftware.mailarchiverx 0x00dd22fb Delegate.IM_Invoke%%o<CCEmailApp.CCEmailApp>sb + 110
4 com.mothsoftware.mailarchiverx 0x00dd23b9 AddHandler.Stub.40%%sb + 83
5 com.mothsoftware.mailarchiverx 0x00aaf031 CCEmailApp.CCEmailApp.LBMailClients_CellAction%%o<CCEmailApp.CCEmailApp>oi4i4 + 1343
6 com.mothsoftware.mailarchiverx 0x00accd41 Delegate.IM_Invoke%%oi4i4 + 103
7 com.mothsoftware.mailarchiverx 0x00accd97 AddHandler.Stub.41%%i4i4 + 74
8 com.mothsoftware.mailarchiverx 0x009fa6cf UndoableListbox.Event_CellAction%%oi4i4 + 1254
9 com.xojo.XojoFramework 0x01dda056 0x1dc4000 + 90198
10 com.xojo.XojoFramework 0x01f1b7ff 0x1dc4000 + 1406975
11 com.xojo.XojoFramework 0x01f1c068 0x1dc4000 + 1409128
12 com.xojo.XojoFramework 0x01f1c13a 0x1dc4000 + 1409338
13 com.xojo.XojoFramework 0x01ee2f81 0x1dc4000 + 1175425
14 com.xojo.XojoFramework 0x01f1b351 0x1dc4000 + 1405777
15 com.xojo.XojoFramework 0x01e193af 0x1dc4000 + 349103
16 com.xojo.XojoFramework 0x01e1414c 0x1dc4000 + 328012
17 com.apple.AppKit 0x983f05b7 -[NSWindow _handleMouseDownEvent:isDelayedEvent:] + 6266
18 com.apple.AppKit 0x983f20ea -[NSWindow _reallySendEvent:isDelayedEvent:] + 2303
19 com.apple.AppKit 0x97c95927 -[NSWindow sendEvent:] + 567
20 com.xojo.XojoFramework 0x01e15628 0x1dc4000 + 333352
21 com.apple.AppKit 0x97c91942 -[NSApplication sendEvent:] + 2919
22 com.xojo.XojoFramework 0x01e043a3 0x1dc4000 + 263075
23 com.xojo.XojoFramework 0x01e043e4 0x1dc4000 + 263140
24 com.mothsoftware.mailarchiverx 0x001a0456 Delegate.Invoke%% + 34
25 com.mothsoftware.mailarchiverx 0x0006de98 Application._CallFunctionWithExceptionHandling%%op + 248
26 com.xojo.XojoFramework 0x01f68f33 0x1dc4000 + 1724211
27 com.xojo.XojoFramework 0x01e04312 0x1dc4000 + 262930
28 com.apple.AppKit 0x97bbc18f -[NSApplication run] + 1159
29 com.xojo.XojoFramework 0x01f68fd9 0x1dc4000 + 1724377
30 com.xojo.XojoFramework 0x01f671ac RuntimeRun + 49
31 com.mothsoftware.mailarchiverx 0x0015ffe9 REALbasic._RuntimeRun + 34
32 com.mothsoftware.mailarchiverx 0x015f9a79 _Main + 257
33 com.mothsoftware.mailarchiverx 0x015f3f0f main + 36
34 com.mothsoftware.mailarchiverx 0x0169f6a4 start + 53

Thread 1:
0 libsystem_kernel.dylib 0x908a6d76 __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x9c00e52d _pthread_wqthread + 1289
2 libsystem_pthread.dylib 0x9c00bf72 start_wqthread + 34

Thread 2:: Dispatch queue: com.apple.libdispatch-manager
0 libsystem_kernel.dylib 0x908a7812 kevent_qos + 10
1 libdispatch.dylib 0x9c8d370e _dispatch_mgr_invoke + 234
2 libdispatch.dylib 0x9c8d32e2 _dispatch_mgr_thread + 52

Thread 3:
0 libsystem_kernel.dylib 0x908a6d76 __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x9c00e52d _pthread_wqthread + 1289
2 libsystem_pthread.dylib 0x9c00bf72 start_wqthread + 34

Thread 4:
0 libsystem_kernel.dylib 0x908a6d76 __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x9c00e52d _pthread_wqthread + 1289
2 libsystem_pthread.dylib 0x9c00bf72 start_wqthread + 34

Thread 5:
0 libsystem_kernel.dylib 0x908a6d76 __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x9c00e52d _pthread_wqthread + 1289
2 libsystem_pthread.dylib 0x9c00bf72 start_wqthread + 34

Thread 6:: com.apple.NSEventThread
0 libsystem_kernel.dylib 0x9089f84a mach_msg_trap + 10
1 libsystem_kernel.dylib 0x9089ec34 mach_msg + 68
2 com.apple.CoreFoundation 0x909cdc46 __CFRunLoopServiceMachPort + 214
3 com.apple.CoreFoundation 0x909cd051 __CFRunLoopRun + 1521
4 com.apple.CoreFoundation 0x909cc7f6 CFRunLoopRunSpecific + 390
5 com.apple.CoreFoundation 0x909cc65b CFRunLoopRunInMode + 123
6 com.apple.AppKit 0x97c8d6aa _NSEventThread + 291
7 libsystem_pthread.dylib 0x9c00ea26 _pthread_body + 138
8 libsystem_pthread.dylib 0x9c00e99c _pthread_start + 155
9 libsystem_pthread.dylib 0x9c00bf96 thread_start + 34

Thread 7:
0 libsystem_kernel.dylib 0x908a6d76 __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x9c00e52d _pthread_wqthread + 1289
2 libsystem_pthread.dylib 0x9c00bf72 start_wqthread + 34

Thread 0 crashed with X86 Thread State (32-bit):
eax: 0x00000001 ebx: 0x00000000 ecx: 0x00000000 edx: 0x000ccccc
edi: 0x0e202328 esi: 0x00000000 ebp: 0xbfffef58 esp: 0xbfffef20
ss: 0x00000023 efl: 0x00210202 eip: 0x011e0b96 cs: 0x0000001b
ds: 0x00000023 es: 0x00000023 fs: 0x00000000 gs: 0x0000000f
cr2: 0xffffffef

Logical CPU: 2
Error Code: 0x00000006
Trap Number: 14

How the code is used is a bit more complicated. The window is similar to the account window in Mail. On the left side there are mail clients and accounts, which can be made active or inactive. For a screenshot see http://www.manual.mothsoftware.com/reference/setup/setup.html . The right side has information about the mail clients and accounts. When you click on the active checkbox then the info is communicated to the account details where it is then saved. And everything is handled with timers, threads and whatnots (critical sections) to avoid gulash.

Here is the high level code of what happens:

[code]Sub MailApplicationActiveChanged(hasMailApplication as String, isActive as Boolean)

'update isActive for the currently selected mail client

if IsLoadingData then Return
KillThreads
if hasMailApplication = MailApplication then theEmailInfo.isActive = isActive <- crash here???

SaveDictionary
EnableDisableAllControls(true)

if isActive then

dim FirstNode as TreeViewNode = TreeViewNode(TVMailbox.NodesOnScreen.Item(0))
if FirstNode.Text = kMakeMailclientActive then CRefreshAction

else

'reset TreeView
dim currentList as integer
for currentList = 0 to UBound(theLists)
  if theLists(currentList) <> nil then Destroy(theLists(currentList))
next
TVMailbox.RemoveAllNodes

'show dummy node
theLoadText = kMakeMailclientActive
dim theNode as new TreeViewNode(theLoadText, nil)
if theNode <> nil then TVMailbox.AppendNode(theNode)

end if

exception exc
theException = new ErrorException(exc, currentMethodName)
End Sub[/code]

if hasMailApplication = MailApplication then theEmailInfo.isActive = isActive <- crash here???

Any chance of theEmailInfo being nil here? I think I’ve seen Xojo fail to raise proper NilObject-Exceptions and crash instead in the past.

@Max: clever idea. Doesn’t seem so. The row with the email client needs to be selected first and here the data is loaded.

The bug so far has occurred a few times. It’s not a head-meets-desk one.

I’ve replaced the computed property with a regular one. Now I’m going to add some logging so that I can see better if the crash log is correct or not.

I second Maximilian. An exception type of “EXC_BAD_ACCESS (SIGSEGV)” is showing that you tried to access objects or memory, which already was released. So theEmailInfo is probably Nil.

What does KillThreads do? Could it be that under certain circumstances it could set theEmailInfo to Nil?

I don’t see the problem.

There are 2 threads, each for getting the mailboxes and the IMAP account. KillThreads kills these if they are running.

When a row with an email client is selected then the data is loaded into theEmailInfo. The mailboxes are part of theEmailInfo. But theEmailInfo is only reset when the mail client selection is changed or an Imap account is selected/created.

The amount of data can be rather large if a user has a lot of mailboxes. There is a timer that saves the data every second. Could this interfere?

I think this won’t solve your problem, but:

I try to avoid such “Timer Monitor & Maintenance” Solutions whenever i can. Isn’t there anything you can use to trigger what the Timer has to do and do it in a Thread?

As a side effect, this could lead to improved resonsivenes of your UI.

@Sascha: you are fully correct. I’ll try to change this.

Since @Michel Bujardet told me that Threads can launch Timers, i regulary use various Events to start Threads which in turn start (once they have finished), Timers which update my UI if needed. Works like a charm. :smiley:

To be more precise: In the past i used Timers which monitored Threads in 100ms Timer.ModeMultiple and when a Thread was NotRunning, the Timer manipulated the UI or made this and that.

Now i start Threads which once they have finished, start Timers with a Period of 50ms in Timer.ModeSingle. Then those Timers manipulate the UI. Now everything is blazing fast and MUCH easier to maintain.

The Xojo examples contain an instructive little project called “UIThreadingWithTask” (in Example Projects/Desktop/UpdatingUIFromThread) which features the Task - class which I use for all task related purposes. Definitely worth checking out. What I like about it is that I can handle what the thread does and how the UI is updated in one single class.

@Max: will have a look. However, the window is waaayyyy to complicated for a simple design. And it’s also way to late to do an architectural change now. I just wonder why I haven’t seen this before and why the beta testers for the internal beta also haven’t seen this.

Good luck
Or bad luck depending on your perspective