Release mode crashes when looping through text files (but not debug)

Hi there,

I'm having a problem with an app i am designing, wondering if someone more knowledgable than myself can help. The app has a "Clip" class which stores various metadata strings about video clips.

As part of the data population routine, the app uses Clip.SourceFolderPath to look into the folder the clip resides in and iterates through the files to find one ending in .KeyKodeList. This is a tab separated text file. The app opens it and iterates through rows (two columns, timecode and keykode, many rows can be upwards of 10,000) until it gets to the timecode values stored in Clip.Start and Clip.End. It then takes the corresponding KeyKode value and stores it in Clip.KKend and Clip.KKstart.

It loops through this process for the 60 odd clips. In debug mode, not a problem. In Release mode, the app still works as I'd expect it (it outputs this info to a text file which does get generated correctly) but any UI interaction stops (theres a message box at the end to say that it's complete) and the app crashes with a bad access error.

Any help to resolve this would be much appreciated (and also code improvement suggestions welcome!)

For reference I have also tried a StreamReader and Buffered StreamReader to no avail.

Thanks

Sam

Code:

                //Get KeyKode file
                fld = clp.SourceFilePath.Substring(0, clp.SourceFilePath.LastIndexOf("/"));
                DirectoryInfo dir = new DirectoryInfo(fld);
                foreach (FileInfo flstr in dir.EnumerateFiles("*.keykodelist"))
                {
                    KK = flstr.FullName;
                    break;
                }
                fld = null;
                dir = null;

                //Iterate through file to find KeyKode
                foreach (string l in File.ReadLines(KK))
                {
                    if (l.Contains(clp.Start))
                    {
                        dataline = l.Split(new string[] { "\t" }, StringSplitOptions.None);
                        clp.KKStart = dataline[0];
                    }

                    if (l.Contains(clp.End))
                    {
                        dataline = l.Split(new string[] { "\t" }, StringSplitOptions.None);
                        clp.KKEnd = dataline[0];
                    }
                }
                KK = null;

Error:

Process: EditStag [52667]
Path: /Users/USER/*/EditStag.app/Contents/MacOS/EditStag
Identifier: com.digital-orchard.EditStag
Version: 1 (2)
Code Type: X86 (Native)
Parent Process: ??? [1]
Responsible: EditStag [52667]
User ID: 501

Date/Time: 2016-12-21 14:24:56.746 +0000
OS Version: Mac OS X 10.11.6 (15G1108)
Report Version: 11
Anonymous UUID: 6D091F19-8E59-93F1-D2FE-3A53BFDD06A4

Sleep/Wake UUID: BD4BFA69-0662-44D7-932A-8525AC563BC5

Time Awake Since Boot: 340000 seconds
Time Since Wake: 1500 seconds

System Integrity Protection: enabled

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

Exception Type: EXC_BAD_ACCESS (SIGABRT)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000d5d7ede7
Exception Note: EXC_CORPSE_NOTIFY

VM Regions Near 0xd5d7ede7:
Stack 00000000bf809000-00000000c0000000 [ 8156K] rw-/rwx SM=COW
-->
Submap 00000000ffff0000-00000000ffff1000 [ 4K] r--/r-- SM=PRV process-only VM submap

Application Specific Information:
abort() called

Thread 0 Crashed:: tid_160b Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x9d56e572 __pthread_kill + 10
1 libsystem_pthread.dylib 0x91afd654 pthread_kill + 101
2 libsystem_c.dylib 0x9c78fc38 abort + 156
3 libmono-2.0.dylib 0x021e93a5 mono_handle_native_sigsegv + 757
4 libmono-2.0.dylib 0x022392c2 mono_arch_handle_altstack_exception + 162 (exceptions-x86.c:1103)
5 libmono-2.0.dylib 0x02127de3 mono_sigsegv_signal_handler + 467 (mini-runtime.c:2883)
6 libsystem_platform.dylib 0x9cfa679b _sigtramp + 43
7 ??? 0xffffffff 0 + 4294967295
8 libmono-2.0.dylib 0x02127c10 0x211a000 + 56336
9 com.apple.Foundation 0x9499224a _NSAddExceptionHandlerForLock + 33
10 com.apple.AppKit 0x99b16e04 _NSAppKitLock + 78
11 com.apple.AppKit 0x99966629 -[NSWindow setDelegate:] + 96
12 com.apple.FinderKit 0x0e3dd325 -[FI_TFloatingInputWindowController dealloc] + 61
13 libobjc.A.dylib 0x97e8adbd objc_object::sidetable_release(bool) + 239
14 libobjc.A.dylib 0x97e8c1e6 -[NSObject release] + 25
15 com.apple.AppKit 0x998fb3c8 -[NSWindowController release] + 153
16 com.apple.FinderKit 0x0e3ddcc1 OBJCRetainReleasePolicy<FI_TFloatingInputWindowController*>::Release(FI_TFloatingInputWindowController*) + 59
17 com.apple.FinderKit 0x0e3ddc79 TRef<FI_TFloatingInputWindowController*, OBJCRetainReleasePolicy<FI_TFloatingInputWindowController*> >::~TRef() + 19
18 libsystem_c.dylib 0x9c79097d __cxa_finalize_ranges + 318
19 libsystem_c.dylib 0x9c790a05 __cxa_finalize + 59
20 libsystem_c.dylib 0x9c790cfa exit + 62
21 libmono-2.0.dylib 0x021e9bea mono_invoke_unhandled_exception_hook + 298
22 libmono-2.0.dylib 0x021e8a1a mono_handle_exception_internal + 6202 (mini-exceptions.c:1797)
23 libmono-2.0.dylib 0x021e71d9 mono_handle_exception + 41 (mini-exceptions.c:2027)
24 libmono-2.0.dylib 0x02238488 mono_x86_throw_exception + 184 (exceptions-x86.c:487)
25 ??? 0x024dec57 0 + 38661207
26 ??? 0x075f6bd4 0 + 123694036
27 libobjc.A.dylib 0x97e8e3ee -[NSObject performSelector:withObject:] + 70
28 com.apple.AppKit 0x99b731bd __36-[NSApplication sendAction:to:from:]_block_invoke + 51
29 libsystem_trace.dylib 0x9577f3c1 _os_activity_initiate + 85
30 com.apple.AppKit 0x99b730de -[NSApplication sendAction:to:from:] + 610
31 com.apple.AppKit 0x99b86991 -[NSControl sendAction:to:] + 102
32 com.apple.AppKit 0x99b86885 __26-[NSCell _sendActionFrom:]_block_invoke + 176
33 libsystem_trace.dylib 0x9577f3c1 _os_activity_initiate + 85
34 com.apple.AppKit 0x99b867b4 -[NSCell _sendActionFrom:] + 161
35 com.apple.AppKit 0x99de8349 __48-[NSCell trackMouse:inRect:ofView:untilMouseUp:]_block_invoke1010 + 43
36 libsystem_trace.dylib 0x9577f3c1 _os_activity_initiate + 85
37 com.apple.AppKit 0x99b84b61 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2744
38 com.apple.AppKit 0x99bd1003 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 809
39 com.apple.AppKit 0x99b83190 -[NSControl mouseDown:] + 693
40 com.apple.AppKit 0x9a17711b -[NSWindow _handleMouseDownEvent:isDelayedEvent:] + 6266
41 com.apple.AppKit 0x9a178922 -[NSWindow _reallySendEvent:isDelayedEvent:] + 2303
42 com.apple.AppKit 0x99b0f7b7 -[NSWindow sendEvent:] + 567
43 com.apple.AppKit 0x99a8ab45 -[NSApplication sendEvent:] + 2919
44 com.apple.AppKit 0x998ddba7 -[NSApplication run] + 1159
45 ??? 0x0959ffa0 0 + 156893088
46 ??? 0x095a20b0 0 + 156901552
47 ??? 0x02525206 0 + 38949382
48 ??? 0x025252d9 0 + 38949593
49 libmono-2.0.dylib 0x0212b6e7 mono_jit_runtime_invoke + 1527 (mini-runtime.c:2547)
50 libmono-2.0.dylib 0x0230f6e0 do_runtime_invoke + 96 (object.c:2809)
51 libmono-2.0.dylib 0x02311f2d mono_runtime_exec_main + 1005 (object.c:4585)
52 libmono-2.0.dylib 0x02311a5f mono_runtime_run_main + 895 (object.c:4135)
53 libmono-2.0.dylib 0x021adad9 mono_jit_exec + 265 (driver.g.c:1050)
54 libmono-2.0.dylib 0x021b0182 mono_main + 8850 (driver.g.c:2187)
55 com.digital-orchard.EditStag 0x0000252f main + 1983
56 com.digital-orchard.EditStag 0x00001d65 start + 53

Thread 1:: SGen worker
0 libsystem_kernel.dylib 0x9d56e3ea __psynch_cvwait + 10
1 libsystem_pthread.dylib 0x91afb538 _pthread_cond_wait + 757
2 libsystem_pthread.dylib 0x91afd276 pthread_cond_wait$UNIX2003 + 71
3 libmono-2.0.dylib 0x0237b175 thread_func + 213 (mono-os-mutex.h:107)
4 libsystem_pthread.dylib 0x91afa780 _pthread_body + 138
5 libsystem_pthread.dylib 0x91afa6f6 _pthread_start + 155
6 libsystem_pthread.dylib 0x91af7f7a thread_start + 34

Thread 2:: Finalizer
0 libsystem_kernel.dylib 0x9d5674d6 semaphore_wait_trap + 10
1 libmono-2.0.dylib 0x02308e57 finalizer_thread + 215 (mono-os-semaphore.h:72)
2 libmono-2.0.dylib 0x022e1a8f start_wrapper + 575 (threads.c:740)
3 libmono-2.0.dylib 0x023ab8ca inner_start_thread + 474 (mono-threads-posix.c:92)
4 libsystem_pthread.dylib 0x91afa780 _pthread_body + 138
5 libsystem_pthread.dylib 0x91afa6f6 _pthread_start + 155
6 libsystem_pthread.dylib 0x91af7f7a thread_start + 34

Thread 3:
0 libsystem_kernel.dylib 0x9d56ed5e __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x91afa34b _pthread_wqthread + 1289
2 libsystem_pthread.dylib 0x91af7f56 start_wqthread + 34

Thread 4:: Dispatch queue: com.apple.libdispatch-manager
0 libsystem_kernel.dylib 0x9d56f7fa kevent_qos + 10
1 libdispatch.dylib 0x9ea9a7ea _dispatch_mgr_invoke + 234
2 libdispatch.dylib 0x9ea9a3be _dispatch_mgr_thread + 52

Thread 5:: tid_2503
0 libsystem_kernel.dylib 0x9d56ed5e __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x91afa34b _pthread_wqthread + 1289
2 libsystem_pthread.dylib 0x91af7f56 start_wqthread + 34

Thread 6:
0 libsystem_kernel.dylib 0x9d56ed5e __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x91afa34b _pthread_wqthread + 1289
2 libsystem_pthread.dylib 0x91af7f56 start_wqthread + 34

Thread 7:
0 libsystem_kernel.dylib 0x9d56ed5e __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x91afa34b _pthread_wqthread + 1289
2 libsystem_pthread.dylib 0x91af7f56 start_wqthread + 34

Thread 8:: com.apple.NSEventThread
0 com.apple.CoreFoundation 0x977f84d6 CFBasicHashFindBucket + 2150
1 com.apple.CoreFoundation 0x9784861b CFSetGetValue + 123
2 com.apple.CoreFoundation 0x9784807e __CFRunLoopFindMode + 174
3 com.apple.CoreFoundation 0x97885678 CFRunLoopRemoveTimer + 104
4 com.apple.CoreFoundation 0x97885302 CFRunLoopTimerInvalidate + 434
5 com.apple.CoreFoundation 0x97884a31 __CFRunLoopDoTimer + 1313
6 com.apple.CoreFoundation 0x9788447d __CFRunLoopDoTimers + 349
7 com.apple.CoreFoundation 0x9787b371 __CFRunLoopRun + 2113
8 com.apple.CoreFoundation 0x9787a8c6 CFRunLoopRunSpecific + 390
9 com.apple.CoreFoundation 0x9787a72b CFRunLoopRunInMode + 123
10 com.apple.AppKit 0x99a52dde _NSEventThread + 291
11 libsystem_pthread.dylib 0x91afa780 _pthread_body + 138
12 libsystem_pthread.dylib 0x91afa6f6 _pthread_start + 155
13 libsystem_pthread.dylib 0x91af7f7a thread_start + 34

Thread 9:: Dispatch queue: TSystemNotificationTask
0 com.apple.CoreServices.FSEvents 0x9dbff02c receive_and_dispatch_rcv_msg + 18
1 libdispatch.dylib 0x9ea9483f _dispatch_client_callout + 50
2 libdispatch.dylib 0x9eaa5698 _dispatch_source_latch_and_call + 2292
3 libdispatch.dylib 0x9ea99032 _dispatch_source_invoke + 881
4 libdispatch.dylib 0x9ea997b6 _dispatch_queue_drain + 1171
5 libdispatch.dylib 0x9eaa0278 _dispatch_queue_invoke + 509
6 libdispatch.dylib 0x9ea9829c _dispatch_root_queue_drain + 491
7 libdispatch.dylib 0x9ea9806b _dispatch_worker_thread3 + 97
8 libsystem_pthread.dylib 0x91afa25c _pthread_wqthread + 1050
9 libsystem_pthread.dylib 0x91af7f56 start_wqthread + 34

Thread 10:
0 libsystem_kernel.dylib 0x9d56ed5e __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x91afa34b _pthread_wqthread + 1289
2 libsystem_pthread.dylib 0x91af7f56 start_wqthread + 34

Thread 11:
0 libsystem_kernel.dylib 0x9d56ed5e __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x91afa34b _pthread_wqthread + 1289
2 libsystem_pthread.dylib 0x91af7f56 start_wqthread + 34

Thread 12:: Dispatch queue: com.apple.root.default-qos
0 libsystem_kernel.dylib 0x9d56e422 psynch_mutexwait + 10
1 libsystem_pthread.dylib 0x91afac62 _pthread_mutex_lock_wait + 99
2 libsystem_pthread.dylib 0x91af826e _pthread_mutex_lock_slow + 277
3 libsystem_pthread.dylib 0x91af813d pthread_mutex_lock + 138
4 com.apple.Foundation 0x9494a8d8 -[NSRecursiveLock lock] + 26
5 com.apple.AppKit 0x99b16dde _NSAppKitLock + 40
6 com.apple.AppKit 0x999b218d -[NSWindow childWindows] + 52
7 com.apple.AppKit 0x99a4466c -[NSWindow _setTransformForAnimation:anchorPoint:] + 661
8 com.apple.AppKit 0x99a442be -[_NSWindowTransformAnimation setWindowMagnification:forProgress:] + 569
9 com.apple.AppKit 0x99a43be0 -[_NSWindowTransformAnimation setCurrentProgress:] + 559
10 com.apple.AppKit 0x99ae7936 -[NSAnimation(NSInternal) _advanceTimeWithDisplayLink:] + 496
11 com.apple.AppKit 0x99ae7741 __58-[NSScreen(NSDisplayLink) displayLinkWithTarget:selector:]_block_invoke + 34
12 com.apple.AppKit 0x99ae7606 -[NSScreenDisplayLink _fire] + 576
13 com.apple.AppKit 0x99ae73c1 __46-[NSScreenDisplayLink initWithScreen:handler:]_block_invoke + 42
14 com.apple.CoreFoundation 0x978f0286 _runLoopTimerWithBlockContext + 22
15 com.apple.CoreFoundation 0x97884f46 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION
+ 22
16 com.apple.CoreFoundation 0x978849f2 __CFRunLoopDoTimer + 1250
17 com.apple.CoreFoundation 0x9788447d __CFRunLoopDoTimers + 349
18 com.apple.CoreFoundation 0x9787b371 __CFRunLoopRun + 2113
19 com.apple.CoreFoundation 0x9787a8c6 CFRunLoopRunSpecific + 390
20 com.apple.CoreFoundation 0x9787a72b CFRunLoopRunInMode + 123
21 com.apple.Foundation 0x9495cc9c -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 296
22 com.apple.AppKit 0x99a460ab -[NSAnimation(NSInternal) _runBlocking] + 498
23 com.apple.AppKit 0x99a45e9d -[NSAnimation(NSInternal) _animationThread] + 80
24 com.apple.AppKit 0x99a45dd1 __42-[NSAnimation(NSInternal) _runInNewThread]_block_invoke + 36
25 libdispatch.dylib 0x9eaa04c5 _dispatch_call_block_and_release + 15
26 libdispatch.dylib 0x9ea9483f _dispatch_client_callout + 50
27 libdispatch.dylib 0x9ea9879c _dispatch_root_queue_drain + 1771
28 libdispatch.dylib 0x9ea9806b _dispatch_worker_thread3 + 97
29 libsystem_pthread.dylib 0x91afa25c _pthread_wqthread + 1050
30 libsystem_pthread.dylib 0x91af7f56 start_wqthread + 34

Thread 13:
0 libsystem_kernel.dylib 0x9d56ed5e __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x91afa34b _pthread_wqthread + 1289
2 libsystem_pthread.dylib 0x91af7f56 start_wqthread + 34

Thread 14:
0 libsystem_kernel.dylib 0x9d56ed5e __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x91afa34b _pthread_wqthread + 1289
2 libsystem_pthread.dylib 0x91af7f56 start_wqthread + 34

Thread 15:
0 libsystem_kernel.dylib 0x9d56ed5e __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x91afa34b _pthread_wqthread + 1289
2 libsystem_pthread.dylib 0x91af7f56 start_wqthread + 34

Thread 16:
0 libsystem_kernel.dylib 0x9d56ed5e __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x91afa34b _pthread_wqthread + 1289
2 libsystem_pthread.dylib 0x91af7f56 start_wqthread + 34

Thread 0 crashed with X86 Thread State (32-bit):
eax: 0x00000000 ebx: 0xa41936b0 ecx: 0x025bb70c edx: 0x00000000
edi: 0xa2eb0000 esi: 0x00000006 ebp: 0x025bb728 esp: 0x025bb70c
ss: 0x00000023 efl: 0x00000206 eip: 0x9d56e572 cs: 0x0000000b
ds: 0x00000023 es: 0x00000023 fs: 0x00000000 gs: 0x0000000f
cr2: 0x00b6e000

Logical CPU: 0
Error Code: 0x00100170
Trap Number: 132

Posts

  • ChrisHamonsChrisHamons USXamarin Team Xamurai
    edited December 2016

    So the fact that we're getting:

    20 libsystem_c.dylib 0x9c790cfa exit + 62
    21 libmono-2.0.dylib 0x021e9bea mono_invoke_unhandled_exception_hook + 298
    22 libmono-2.0.dylib 0x021e8a1a mono_handle_exception_internal + 6202 (mini-exceptions.c:1797)
    23 libmono-2.0.dylib 0x021e71d9 mono_handle_exception + 41 (mini-exceptions.c:2027)
    24 libmono-2.0.dylib 0x02238488 mono_x86_throw_exception + 184 (exceptions-x86.c:487)
    25 ??? 0x024dec57 0 + 38661207
    26 ??? 0x075f6bd4 0 + 123694036
    27 libobjc.A.dylib 0x97e8e3ee -[NSObject performSelector:withObject:] + 70
    28 com.apple.AppKit 0x99b731bd __36-[NSApplication sendAction:to:from:]_block_invoke + 51

    and then crashing harder makes me think this is going on:

    • We're trying to invoke some action on a dead object
    • We start crashing, so we call exit
    • Which tries to do more cleanup - 16 com.apple.FinderKit 0x0e3ddcc1 OBJCRetainReleasePolicy<FI_TFloatingInputWindowController>::Release(FI_TFloatingInputWindowController) + 59
    • And that does bad things
    • But we are literally already crashing, so ¯\_(ツ)_/¯

    So let's figure out the original crash. Often release vs debug are timing related issues, sometimes exposing garbage collection / memory allocation issues. So let's try a few approaches:

    • Add this code somewhere after startup. It'll hopefully make the crash more consistent.
    new System.Threading.Thread (() => 
        {
            while (true) {
                System.Threading.Thread.Sleep (1000);
                GC.Collect ();
            }
        }).Start ();  
    
    • Try running your application in Instruments with the Zombies template. That will often catch and describe what object got killed underneath us.

    • Post your Xamarin.Mac version.

    • I see nothing obviously wrong in your mini example.
  • samspurgeonsamspurgeon GBMember

    Thanks Chris, your advice is much appreciated - Xamarin.Mac version details below. I'll add in the garbage collection routine and see how it affects things and also run the Zombie template, I did try this before but didn't really know what I was looking at - will research more and try again (but after Christmas!)

    Thanks again

    Sam

    === Xamarin Studio Community ===

    Version 6.1.3 (build 19)
    Installation UUID: 50640a8a-782d-4caf-b9ac-1deb2eca3adc
    Runtime:
    Mono 4.6.2 (mono-4.6.0-branch/ac9e222) (64-bit)
    GTK+ 2.24.23 (Raleigh theme)

    Package version: 406020016
    

    === NuGet ===

    Version: 3.4.3.0

    === Apple Developer Tools ===

    Xcode 8.1 (11544)
    Build 8B62

    === Xamarin.Mac ===

    Version: 2.10.0.120 (Xamarin Studio Community)

    === Build Information ===

    Release ID: 601030019
    Git revision: 7fabf9293c2d7b638e28a07f798d21799da1f886
    Build date: 2016-12-21 07:08:35-05
    Xamarin addins: efbae0e683a0060d2230e91e70c1598abc054845
    Build lane: monodevelop-lion-cycle8

    === Operating System ===

    Mac OS X 10.11.6
    Darwin Sams-MacBook-Pro.local 15.6.0 Darwin Kernel Version 15.6.0
    Thu Sep 1 15:01:16 PDT 2016
    root:xnu-3248.60.11~2/RELEASE_X86_64 x86_64

  • samspurgeonsamspurgeon GBMember

    @ChrisHamons thanks again for your post - quick update, it seems that the problem does not occur in Xamarin.Mac 3.0 so I am treating it as a Xamarin bug - hopefully a stable version of v3 will be available soon!

Sign In or Register to comment.