Crash iterating through numerous text files

samspurgeonsamspurgeon GBMember
edited December 2016 in Xamarin.Mac

Hi, I am reasonably new at this so apologies if this is an obvious question:

I have written a tool that populates a "Clip" class with metadata about video clips (this bit works fine). The tool attempts to add "KeyKode" metadata to the Clip class by finding a tab delimited text file in the clip's source folder (clip.SourceFilePath) and then searching for the clip's start and end timecodes (there is one KeyKode number for each of these timecode values stored in the tab delimited text). The below code I use to achieve this works fine in debug mode but not in release mode (giving a EXC_BAD_ACCESS (SIGABRT) crash error). If I comment out the section of code starting with "//Get KeyKode from Timecode", it works fine in both mode.

As far as the method used to read the text file, I have also tried a StreamReader and Buffered StreamReader to no avail. the KeyKodeList text file can contain 10,000 lines.

Any advice appreciated, including code improvements!

Thanks

Sam

Code:

//Iterate through clips
string KK = "";
string[] dataline;
string fld;
foreach (ClipMeta clp in ClipMetaList)
{
    //Get KeyKode File
    fld = clp.SourceFilePath.Substring(0, clp.SourceFilePath.LastIndexOf("/"));
    DirectoryInfo dir = new DirectoryInfo(fld);
    var kkFiles = dir.EnumerateFiles("*.keykodelist");
    List<FileInfo> kkFileList = new List<FileInfo>(kkFiles);
    foreach (FileInfo flstr in kkFileList)
    {
        KK = flstr.FullName;
        break;
    }
    fld = null;
    dir = null;
    kkFileList = null;
    kkFiles = null;

    //Get KeyKode from Timecode
    List<string> kkList = new List<string>(File.ReadAllLines(KK));
    foreach (string ln in kkList)
    {
        if (ln.Contains(clp.Start))
        {
            dataline = ln.Split(new string[] { "\t" }, StringSplitOptions.None);
            clp.KKStart = dataline[0];
        }
        if (ln.Contains(clp.End))
        {
            dataline = ln.Split(new string[] { "\t" }, StringSplitOptions.None);
            clp.KKEnd = dataline[0];
        }
    }
    KK = null;
    kkList = null;
}

Error:

Process: EditStag [92575]
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 [92575]
User ID: 501

Date/Time: 2016-12-20 20:24:22.510 +0000
OS Version: Mac OS X 10.11.6 (15G1004)
Report Version: 11
Anonymous UUID: EB8FA38E-D7A2-E240-1129-B2C587AC0AE1

Time Awake Since Boot: 620000 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 0x0000000000000017
Exception Note: EXC_CORPSE_NOTIFY

VM Regions Near 0x17:
-->
__TEXT 0000000000001000-0000000000004000 [ 12K] r-x/rwx SM=COW /Users/USER/*/EditStag.app/Contents/MacOS/EditStag

Application Specific Information:
Performing @selector(GenerateReport:) from sender NSButton 0x10c380
abort() called

Thread 0 Crashed:: tid_160b Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x94706572 __pthread_kill + 10
1 libsystem_pthread.dylib 0x9c5f6654 pthread_kill + 101
2 libsystem_c.dylib 0x940c7c38 abort + 156
3 libmono-2.0.dylib 0x018cf3a5 mono_handle_native_sigsegv + 757
4 libmono-2.0.dylib 0x0191f2c2 mono_arch_handle_altstack_exception + 162 (exceptions-x86.c:1103)
5 libmono-2.0.dylib 0x0180dde3 mono_sigsegv_signal_handler + 467 (mini-runtime.c:2883)
6 libsystem_platform.dylib 0x9c50a79b _sigtramp + 43
7 ??? 0xffffffff 0 + 4294967295
8 libmono-2.0.dylib 0x0180dc10 0x1800000 + 56336
9 com.apple.Foundation 0x96c4524a _NSAddExceptionHandlerForLock + 33
10 com.apple.AppKit 0x90e4fe04 _NSAppKitLock + 78
11 com.apple.AppKit 0x90c9f629 -[NSWindow setDelegate:] + 96
12 com.apple.FinderKit 0x0f8ae325 -[FI_TFloatingInputWindowController dealloc] + 61
13 libobjc.A.dylib 0x93b14dbd objc_object::sidetable_release(bool) + 239
14 libobjc.A.dylib 0x93b161e6 -[NSObject release] + 25
15 com.apple.AppKit 0x90c343c8 -[NSWindowController release] + 153
16 com.apple.FinderKit 0x0f8aecc1 OBJCRetainReleasePolicy<FI_TFloatingInputWindowController*>::Release(FI_TFloatingInputWindowController*) + 59
17 com.apple.FinderKit 0x0f8aec79 TRef<FI_TFloatingInputWindowController*, OBJCRetainReleasePolicy<FI_TFloatingInputWindowController*> >::~TRef() + 19
18 libsystem_c.dylib 0x940c897d __cxa_finalize_ranges + 318
19 libsystem_c.dylib 0x940c8a05 __cxa_finalize + 59
20 libsystem_c.dylib 0x940c8cfa exit + 62
21 libmono-2.0.dylib 0x018cfbea mono_invoke_unhandled_exception_hook + 298
22 libmono-2.0.dylib 0x018cea1a mono_handle_exception_internal + 6202 (mini-exceptions.c:1797)
23 libmono-2.0.dylib 0x018cd1d9 mono_handle_exception + 41 (mini-exceptions.c:2027)
24 libmono-2.0.dylib 0x0191e488 mono_x86_throw_exception + 184 (exceptions-x86.c:487)
25 ??? 0x0051ac57 0 + 5352535
26 ??? 0x0a406bd4 0 + 171994068
27 libobjc.A.dylib 0x93b183ee -[NSObject performSelector:withObject:] + 70
28 com.apple.AppKit 0x90eac1bd __36-[NSApplication sendAction:to:from:]_block_invoke + 51
29 libsystem_trace.dylib 0x9caf53c1 _os_activity_initiate + 85
30 com.apple.AppKit 0x90eac0de -[NSApplication sendAction:to:from:] + 610
31 com.apple.AppKit 0x90ebf991 -[NSControl sendAction:to:] + 102
32 com.apple.AppKit 0x90ebf885 __26-[NSCell _sendActionFrom:]_block_invoke + 176
33 libsystem_trace.dylib 0x9caf53c1 _os_activity_initiate + 85
34 com.apple.AppKit 0x90ebf7b4 -[NSCell _sendActionFrom:] + 161
35 com.apple.AppKit 0x91121349 __48-[NSCell trackMouse:inRect:ofView:untilMouseUp:]_block_invoke1010 + 43
36 libsystem_trace.dylib 0x9caf53c1 _os_activity_initiate + 85
37 com.apple.AppKit 0x90ebdb61 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2744
38 com.apple.AppKit 0x90f0a003 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 809
39 com.apple.AppKit 0x90ebc190 -[NSControl mouseDown:] + 693
40 com.apple.AppKit 0x914b011b -[NSWindow _handleMouseDownEvent:isDelayedEvent:] + 6266
41 com.apple.AppKit 0x914b1922 -[NSWindow _reallySendEvent:isDelayedEvent:] + 2303
42 com.apple.AppKit 0x90e487b7 -[NSWindow sendEvent:] + 567
43 com.apple.AppKit 0x90dc3b45 -[NSApplication sendEvent:] + 2919
44 com.apple.AppKit 0x90c16ba7 -[NSApplication run] + 1159
45 ??? 0x0a481fa0 0 + 172498848
46 ??? 0x0a4840a0 0 + 172507296
47 ??? 0x00561206 0 + 5640710
48 ??? 0x005612d9 0 + 5640921
49 libmono-2.0.dylib 0x018116e7 mono_jit_runtime_invoke + 1527 (mini-runtime.c:2547)
50 libmono-2.0.dylib 0x019f56e0 do_runtime_invoke + 96 (object.c:2809)
51 libmono-2.0.dylib 0x019f7f2d mono_runtime_exec_main + 1005 (object.c:4585)
52 libmono-2.0.dylib 0x019f7a5f mono_runtime_run_main + 895 (object.c:4135)
53 libmono-2.0.dylib 0x01893ad9 mono_jit_exec + 265 (driver.g.c:1050)
54 libmono-2.0.dylib 0x01896182 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 0x947063ea __psynch_cvwait + 10
1 libsystem_pthread.dylib 0x9c5f4538 _pthread_cond_wait + 757
2 libsystem_pthread.dylib 0x9c5f6276 pthread_cond_wait$UNIX2003 + 71
3 libmono-2.0.dylib 0x01a61175 thread_func + 213 (mono-os-mutex.h:107)
4 libsystem_pthread.dylib 0x9c5f3780 _pthread_body + 138
5 libsystem_pthread.dylib 0x9c5f36f6 _pthread_start + 155
6 libsystem_pthread.dylib 0x9c5f0f7a thread_start + 34

Thread 2:: Finalizer
0 libsystem_kernel.dylib 0x946ff4d6 semaphore_wait_trap + 10
1 libmono-2.0.dylib 0x019eee57 finalizer_thread + 215 (mono-os-semaphore.h:72)
2 libmono-2.0.dylib 0x019c7a8f start_wrapper + 575 (threads.c:740)
3 libmono-2.0.dylib 0x01a918ca inner_start_thread + 474 (mono-threads-posix.c:92)
4 libsystem_pthread.dylib 0x9c5f3780 _pthread_body + 138
5 libsystem_pthread.dylib 0x9c5f36f6 _pthread_start + 155
6 libsystem_pthread.dylib 0x9c5f0f7a thread_start + 34

Thread 3:
0 libsystem_platform.dylib 0x9c50a1cd _OSSpinLockLockSlow + 71
1 libsystem_platform.dylib 0x9c509a12 _os_lock_spin_lock + 34
2 libsystem_malloc.dylib 0x97e5e2f9 szone_free + 581
3 libdispatch.dylib 0x9061dd2a _dispatch_continuation_free_to_heap + 33
4 libdispatch.dylib 0x9061dcfd _dispatch_cache_cleanup + 23
5 libsystem_pthread.dylib 0x9c5f52e9 _pthread_tsd_cleanup + 613
6 libsystem_pthread.dylib 0x9c5f4e22 _pthread_exit + 108
7 libsystem_pthread.dylib 0x9c5f3354 _pthread_wqthread + 1298
8 libsystem_pthread.dylib 0x9c5f0f56 start_wqthread + 34

Thread 4:: Dispatch queue: com.apple.libdispatch-manager
0 libdispatch.dylib 0x9062c4ce _dispatch_timers_run + 426
1 libdispatch.dylib 0x9061d73c _dispatch_mgr_invoke + 60
2 libdispatch.dylib 0x9061d3be _dispatch_mgr_thread + 52

Thread 5:
0 libsystem_pthread.dylib 0x9c5f334f _pthread_wqthread + 1293
1 libsystem_pthread.dylib 0x9c5f0f56 start_wqthread + 34

Thread 6:
0 libsystem_platform.dylib 0x9c50a1d0 _OSSpinLockLockSlow + 74
1 libsystem_platform.dylib 0x9c509a12 _os_lock_spin_lock + 34
2 libsystem_malloc.dylib 0x97e5e2f9 szone_free + 581
3 libdispatch.dylib 0x9061dd2a _dispatch_continuation_free_to_heap + 33
4 libdispatch.dylib 0x9061dcfd _dispatch_cache_cleanup + 23
5 libsystem_pthread.dylib 0x9c5f52e9 _pthread_tsd_cleanup + 613
6 libsystem_pthread.dylib 0x9c5f4e22 _pthread_exit + 108
7 libsystem_pthread.dylib 0x9c5f3354 _pthread_wqthread + 1298
8 libsystem_pthread.dylib 0x9c5f0f56 start_wqthread + 34

Thread 7:
0 libsystem_malloc.dylib 0x97e5cab4 tiny_free_list_add_ptr + 83
1 libsystem_malloc.dylib 0x97e5bcb8 szone_free_definite_size + 1849
2 libsystem_malloc.dylib 0x97e5b20e free + 301
3 libsystem_pthread.dylib 0x9c5f529d _pthread_tsd_cleanup + 537
4 libsystem_pthread.dylib 0x9c5f4e22 _pthread_exit + 108
5 libsystem_pthread.dylib 0x9c5f3354 _pthread_wqthread + 1298
6 libsystem_pthread.dylib 0x9c5f0f56 start_wqthread + 34

Thread 8:: com.apple.NSEventThread
0 libsystem_kernel.dylib 0x946ff49a mach_msg_trap + 10
1 libsystem_kernel.dylib 0x946fe884 mach_msg + 68
2 com.apple.CoreGraphics 0x91d3266d CGSSnarfAndDispatchDatagrams + 740
3 com.apple.CoreGraphics 0x91d321b5 CGSGetNextEventRecordInternal + 78
4 com.apple.CoreGraphics 0x91d3211f CGEventCreateNextEvent + 34
5 com.apple.HIToolbox 0x9cb5c53b PullEventsFromWindowServerOnConnection(unsigned int, unsigned char, CFMachPortBoost) + 83
6 com.apple.HIToolbox 0x9cb5c4c3 MessageHandler(__CFMachPort
, void*, long, void*) + 55
7 com.apple.CoreFoundation 0x9d53329e __CFMachPortPerform + 270
8 com.apple.CoreFoundation 0x9d533185 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION
+ 53
9 com.apple.CoreFoundation 0x9d5330f0 __CFRunLoopDoSource1 + 512
10 com.apple.CoreFoundation 0x9d52a639 __CFRunLoopRun + 2649
11 com.apple.CoreFoundation 0x9d529976 CFRunLoopRunSpecific + 390
12 com.apple.CoreFoundation 0x9d5297db CFRunLoopRunInMode + 123
13 com.apple.AppKit 0x90d8bdde _NSEventThread + 291
14 libsystem_pthread.dylib 0x9c5f3780 _pthread_body + 138
15 libsystem_pthread.dylib 0x9c5f36f6 _pthread_start + 155
16 libsystem_pthread.dylib 0x9c5f0f7a thread_start + 34

Thread 9:
0 libsystem_malloc.dylib 0x97e5cacf tiny_free_list_add_ptr + 110
1 libsystem_malloc.dylib 0x97e5e908 szone_free + 2132
2 libdispatch.dylib 0x9061dd2a _dispatch_continuation_free_to_heap + 33
3 libdispatch.dylib 0x9061dcfd _dispatch_cache_cleanup + 23
4 libsystem_pthread.dylib 0x9c5f52e9 _pthread_tsd_cleanup + 613
5 libsystem_pthread.dylib 0x9c5f4e22 _pthread_exit + 108
6 libsystem_pthread.dylib 0x9c5f3354 _pthread_wqthread + 1298
7 libsystem_pthread.dylib 0x9c5f0f56 start_wqthread + 34

Thread 10:
0 libsystem_pthread.dylib 0x9c5f2ea8 _pthread_wqthread + 102
1 libsystem_pthread.dylib 0x9c5f0f56 start_wqthread + 34

Thread 11:
0 libsystem_malloc.dylib 0x97e5cacf tiny_free_list_add_ptr + 110
1 libsystem_malloc.dylib 0x97e5bcb8 szone_free_definite_size + 1849
2 libsystem_malloc.dylib 0x97e5b20e free + 301
3 libsystem_pthread.dylib 0x9c5f529d _pthread_tsd_cleanup + 537
4 libsystem_pthread.dylib 0x9c5f4e22 _pthread_exit + 108
5 libsystem_pthread.dylib 0x9c5f3354 _pthread_wqthread + 1298
6 libsystem_pthread.dylib 0x9c5f0f56 start_wqthread + 34

Thread 12:
0 libsystem_platform.dylib 0x9c509823 OSSpinLockLock + 11
1 libsystem_pthread.dylib 0x9c5f3354 _pthread_wqthread + 1298
2 libsystem_pthread.dylib 0x9c5f0f56 start_wqthread + 34

Thread 13:
0 libsystem_platform.dylib 0x9c509c30 OSAtomicCompareAndSwapPtrBarrier$VARIANT$mp + 12
1 com.apple.SystemConfiguration 0x9dbd736e __SCThreadSpecificDataFinalize + 62
2 libsystem_pthread.dylib 0x9c5f529d _pthread_tsd_cleanup + 537
3 libsystem_pthread.dylib 0x9c5f4e22 _pthread_exit + 108
4 libsystem_pthread.dylib 0x9c5f3354 _pthread_wqthread + 1298
5 libsystem_pthread.dylib 0x9c5f0f56 start_wqthread + 34

Thread 14:
0 libsystem_pthread.dylib 0x9c5f334f _pthread_wqthread + 1293
1 libsystem_pthread.dylib 0x9c5f0f56 start_wqthread + 34

Thread 15:
0 libsystem_pthread.dylib 0x9c5f334f _pthread_wqthread + 1293
1 libsystem_pthread.dylib 0x9c5f0f56 start_wqthread + 34

Thread 16:
0 libsystem_kernel.dylib 0x946ff596 syscall_thread_switch + 10
1 libsystem_platform.dylib 0x9c50a1c0 _OSSpinLockLockSlow + 58
2 libsystem_platform.dylib 0x9c509a12 _os_lock_spin_lock + 34
3 libsystem_malloc.dylib 0x97e5e2f9 szone_free + 581
4 libdispatch.dylib 0x9061dd2a _dispatch_continuation_free_to_heap + 33
5 libdispatch.dylib 0x9061dcfd _dispatch_cache_cleanup + 23
6 libsystem_pthread.dylib 0x9c5f52e9 _pthread_tsd_cleanup + 613
7 libsystem_pthread.dylib 0x9c5f4e22 _pthread_exit + 108
8 libsystem_pthread.dylib 0x9c5f3354 _pthread_wqthread + 1298
9 libsystem_pthread.dylib 0x9c5f0f56 start_wqthread + 34

Thread 17:
0 libsystem_malloc.dylib 0x97e5cacf tiny_free_list_add_ptr + 110
1 libsystem_malloc.dylib 0x97e5e908 szone_free + 2132
2 libdispatch.dylib 0x9061dd2a _dispatch_continuation_free_to_heap + 33
3 libdispatch.dylib 0x9061dcfd _dispatch_cache_cleanup + 23
4 libsystem_pthread.dylib 0x9c5f52e9 _pthread_tsd_cleanup + 613
5 libsystem_pthread.dylib 0x9c5f4e22 _pthread_exit + 108
6 libsystem_pthread.dylib 0x9c5f3354 _pthread_wqthread + 1298
7 libsystem_pthread.dylib 0x9c5f0f56 start_wqthread + 34

Thread 18:
0 libsystem_kernel.dylib 0x946ff596 syscall_thread_switch + 10
1 libsystem_platform.dylib 0x9c50a1c0 _OSSpinLockLockSlow + 58
2 libsystem_platform.dylib 0x9c509a12 _os_lock_spin_lock + 34
3 libsystem_malloc.dylib 0x97e5e2f9 szone_free + 581
4 libdispatch.dylib 0x9061dd2a _dispatch_continuation_free_to_heap + 33
5 libdispatch.dylib 0x9061dcfd _dispatch_cache_cleanup + 23
6 libsystem_pthread.dylib 0x9c5f52e9 _pthread_tsd_cleanup + 613
7 libsystem_pthread.dylib 0x9c5f4e22 _pthread_exit + 108
8 libsystem_pthread.dylib 0x9c5f3354 _pthread_wqthread + 1298
9 libsystem_pthread.dylib 0x9c5f0f56 start_wqthread + 34

Thread 19:
0 libsystem_malloc.dylib 0x97e5e5f4 szone_free + 1344
1 libdispatch.dylib 0x9061dd2a _dispatch_continuation_free_to_heap + 33
2 libdispatch.dylib 0x9061dcfd _dispatch_cache_cleanup + 23
3 libsystem_pthread.dylib 0x9c5f52e9 _pthread_tsd_cleanup + 613
4 libsystem_pthread.dylib 0x9c5f4e22 _pthread_exit + 108
5 libsystem_pthread.dylib 0x9c5f3354 _pthread_wqthread + 1298
6 libsystem_pthread.dylib 0x9c5f0f56 start_wqthread + 34

Thread 20:
0 libsystem_platform.dylib 0x9c509823 OSSpinLockLock + 11
1 libsystem_pthread.dylib 0x9c5f3354 _pthread_wqthread + 1298
2 libsystem_pthread.dylib 0x9c5f0f56 start_wqthread + 34

Thread 21:
0 libsystem_kernel.dylib 0x946ff596 syscall_thread_switch + 10
1 libsystem_platform.dylib 0x9c50a1c0 _OSSpinLockLockSlow + 58
2 libsystem_platform.dylib 0x9c509a12 _os_lock_spin_lock + 34
3 libsystem_malloc.dylib 0x97e5e2f9 szone_free + 581
4 libdispatch.dylib 0x9061dd2a _dispatch_continuation_free_to_heap + 33
5 libdispatch.dylib 0x9061dcfd _dispatch_cache_cleanup + 23
6 libsystem_pthread.dylib 0x9c5f52e9 _pthread_tsd_cleanup + 613
7 libsystem_pthread.dylib 0x9c5f4e22 _pthread_exit + 108
8 libsystem_pthread.dylib 0x9c5f3354 _pthread_wqthread + 1298
9 libsystem_pthread.dylib 0x9c5f0f56 start_wqthread + 34

Sign In or Register to comment.