ooper-shlab / SourceView-Swift

A translation of Apple's sample code for Mac "SourceView: Using NSOutlineView with NSTreeController" into Swift
Other
27 stars 7 forks source link

Crash on adding new item #2

Open znafets opened 6 years ago

znafets commented 6 years ago

Reproduce: build, run

  1. click on '+' to add new item -> crash

backtrace:

bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
    frame #0: 0x0000000100a81266 libdispatch.dylib`_dispatch_barrier_sync_f_slow + 835
    frame #1: 0x00000001085ff1de __lldb_backtrace_recording_get_thread_item_info`::__lldb_backtrace_recording_get_thread_item_info(return_buffer=0x00007fff5fbfcc40, debug=24960, thread_id=4320725592, page_to_free=0x0000000100b31000, page_to_free_size=4295183552) at //Parse:94
  * frame #2: 0x0000000100033267 SourceView`IconViewController.(inObject=Any @ 0x00007fff5fbfccb0, self=0x00006180000e2900, contentArray=0x00007fff5fbfcc58) -> ()).(closure #1) at IconViewController.swift:134
    frame #3: 0x0000000100033450 SourceView`thunk at IconViewController.swift:0
    frame #4: 0x0000000100034d11 SourceView`partial apply for thunk at IconViewController.swift:0
    frame #5: 0x000000010096b5d8 libswiftObjectiveC.dylib`ObjectiveC.autoreleasepool <A> (invoking : () throws -> A) throws -> A + 56
    frame #6: 0x0000000100032020 SourceView`IconViewController.gatherContents(inObject=Any @ 0x00007fff5fbfccb0, self=0x00006180000e2900) -> () at IconViewController.swift:135
    frame #7: 0x0000000100031b48 SourceView`IconViewController.didSetBaseNode(oldBaseNode=nil, self=0x00006180000e2900) -> () at IconViewController.swift:68
    frame #8: 0x000000010003158e SourceView`IconViewController.baseNode.didset(oldValue=nil, self=0x00006180000e2900) at IconViewController.swift:36
    frame #9: 0x000000010003153a SourceView`IconViewController.baseNode.setter(newValue=0x0000618000267b80, self=0x00006180000e2900) at IconViewController.swift:0
    frame #10: 0x000000010001a064 SourceView`MyOutlineViewController.viewControllerForSelection(selection=1 value, self=0x0000618000140580) -> NSViewController? at MyOutlineViewController.swift:488
    frame #11: 0x000000010000930e SourceView`MySplitViewController.observeValue(keyPath="selectedObjects", object=some, change=2 key/value pairs, context=nil, self=0x00006180001020a0) -> () at MySplitViewController.swift:114
    frame #12: 0x0000000100009d2d SourceView`@objc MySplitViewController.observeValue(forKeyPath : String?, of : Any?, change : [NSKeyValueChangeKey : Any]?, context : UnsafeMutableRawPointer?) -> () at MySplitViewController.swift:0
    frame #13: 0x00007fffcd6a235d Foundation`NSKeyValueNotifyObserver + 350
    frame #14: 0x00007fffcd719834 Foundation`-[NSObject(NSKeyValueObservingPrivate) _notifyObserversForKeyPath:change:] + 990
    frame #15: 0x00007fffc993c00d AppKit`-[NSController _notifyObserversForKeyPath:change:] + 194
    frame #16: 0x00007fffc9a4daf2 AppKit`-[NSTreeController _didChangeValuesForArrangedKeys:objectKeys:indexPathKeys:] + 192
    frame #17: 0x00007fffc9fdb9c9 AppKit`-[NSTreeController _insertObject:atArrangedObjectIndexPath:objectHandler:] + 538
    frame #18: 0x0000000100013564 SourceView`MyOutlineViewController.performAddFolder(treeAddition=0x0000618000267c00, self=0x0000618000140580) -> () at MyOutlineViewController.swift:214
    frame #19: 0x000000010001693f SourceView`MyOutlineViewController.addFolderWithName(folderName="Untitled", self=0x0000618000140580) -> () at MyOutlineViewController.swift:371
    frame #20: 0x00000001000169b1 SourceView`MyOutlineViewController.addFolder(notif=Foundation.Notification @ 0x00007fff5fbfdb10, self=0x0000618000140580) -> () at MyOutlineViewController.swift:380
    frame #21: 0x0000000100016a67 SourceView`@objc MyOutlineViewController.addFolder(Notification) -> () at MyOutlineViewController.swift:0
    frame #22: 0x00007fffcbc8445c CoreFoundation`__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
    frame #23: 0x00007fffcbc8435b CoreFoundation`_CFXRegistrationPost + 427
    frame #24: 0x00007fffcbc840c2 CoreFoundation`___CFXNotificationPost_block_invoke + 50
    frame #25: 0x00007fffcbc41523 CoreFoundation`-[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1827
    frame #26: 0x00007fffcbc4055c CoreFoundation`_CFXNotificationPost + 604
    frame #27: 0x00007fffcd665677 Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] + 66
    frame #28: 0x0000000100005b7f SourceView`PrimaryViewController.addFolderAction(_0=0x00007fff5fbfe698, self=0x0000600000102fd0) -> () at PrimaryViewController.swift:154
    frame #29: 0x0000000100005c36 SourceView`@objc PrimaryViewController.addFolderAction(AnyObject) -> () at PrimaryViewController.swift:0
    frame #30: 0x00007fffe16203a7 libsystem_trace.dylib`_os_activity_initiate_impl + 53
    frame #31: 0x00007fffc9ee5721 AppKit`-[NSApplication(NSResponder) sendAction:to:from:] + 456
    frame #32: 0x00007fffc99c9cc4 AppKit`-[NSControl sendAction:to:] + 86
    frame #33: 0x00007fffc99c9bec AppKit`__26-[NSCell _sendActionFrom:]_block_invoke + 136
    frame #34: 0x00007fffe16203a7 libsystem_trace.dylib`_os_activity_initiate_impl + 53
    frame #35: 0x00007fffc99c9b44 AppKit`-[NSCell _sendActionFrom:] + 128
    frame #36: 0x00007fffc9a0c539 AppKit`-[NSButtonCell _sendActionFrom:] + 98
    frame #37: 0x00007fffe16203a7 libsystem_trace.dylib`_os_activity_initiate_impl + 53
    frame #38: 0x00007fffc99c8426 AppKit`-[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2481
    frame #39: 0x00007fffc9a0c272 AppKit`-[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 798
    frame #40: 0x00007fffc99c6ddb AppKit`-[NSControl mouseDown:] + 832
    frame #41: 0x00007fffca06124f AppKit`-[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 6341
    frame #42: 0x00007fffca05da6c AppKit`-[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 1942
    frame #43: 0x00007fffca05cf0a AppKit`-[NSWindow(NSEventRouting) sendEvent:] + 541
    frame #44: 0x00007fffc9ee1681 AppKit`-[NSApplication(NSEvent) sendEvent:] + 1145
    frame #45: 0x00007fffc975c427 AppKit`-[NSApplication run] + 1002
    frame #46: 0x00007fffc9726e0e AppKit`NSApplicationMain + 1237
    frame #47: 0x000000010002ef0d SourceView`main at AppDelegate.swift:20
    frame #48: 0x00007fffe13ee235 libdyld.dylib`start + 1
    frame #49: 0x00007fffe13ee235 libdyld.dylib`start + 1
ooper-shlab commented 6 years ago

Thanks for reporting the issue. I have tried to fix it and committed a new version of the code. Please check it.

znafets commented 6 years ago

Yup, crash is fixed, but playing a bit with it reveals other issues like #3

ooper-shlab commented 6 years ago

Thanks for checking. As you see. this repository is so far from fully tested and I really appreciate your contribution. I'll work on the other issue when I'm ready.