我已经对AudioKit的代码进行了更新,现在(开发分支上的)游乐场无法正常工作,在研究中我发现了一个奇怪的情况,
var oscillator = AKOscillator()
产生崩溃,但只需使用该类的一个琐碎子类即可:
class AKSubclassOfOscillator: AKOscillator {}
var oscillator = AKSubclassOfOscillator()
效果很好。有人可以阐明这可能如何发生吗?这个Swift Playground在Xcode 10中正在运行/崩溃。应用程序中的类似代码不会崩溃,仅在操场内部不会崩溃。
这是日志
Playground execution failed:
error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x0).
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
* frame #0: 0x000000010c8b2d2f libswiftCore.dylib`swift_getObjectType + 47
frame #1: 0x000000010c86a855 libswiftCore.dylib`findDynamicValueAndType(swift::OpaqueValue*, swift::TargetMetadata<swift::InProcess> const*, swift::OpaqueValue*&, swift::TargetMetadata<swift::InProcess> const*&, bool&, bool, bool) + 245
frame #2: 0x000000010c86efa7 libswiftCore.dylib`_dynamicCastToExistential(swift::OpaqueValue*, swift::OpaqueValue*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetExistentialTypeMetadata<swift::InProcess> const*, swift::DynamicCastFlags) + 135
frame #3: 0x000000010cbda1b7 PlaygroundLogger`___lldb_unnamed_symbol258$$PlaygroundLogger + 599
frame #4: 0x000000010cbdc8e6 PlaygroundLogger`___lldb_unnamed_symbol269$$PlaygroundLogger + 262
frame #5: 0x000000010cbdf02c PlaygroundLogger`___lldb_unnamed_symbol298$$PlaygroundLogger + 76
frame #6: 0x000000010cbdf6f9 PlaygroundLogger`___lldb_unnamed_symbol333$$PlaygroundLogger + 9
frame #7: 0x000000010cbdf07f PlaygroundLogger`___lldb_unnamed_symbol300$$PlaygroundLogger + 31
frame #8: 0x000000010cbdf609 PlaygroundLogger`___lldb_unnamed_symbol318$$PlaygroundLogger + 9
frame #9: 0x000000010c58a50f libswiftCore.dylib`(extension in Swift):Swift.Collection.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 527
frame #10: 0x000000010c6d600e libswiftCore.dylib`protocol witness for Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> in conformance Swift.LazyMapCollection<A, B> : Swift.Sequence in Swift + 78
frame #11: 0x000000010c783347 libswiftCore.dylib`Swift._RandomAccessCollectionBox._map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 135
frame #12: 0x000000010cbdcbaf PlaygroundLogger`___lldb_unnamed_symbol270$$PlaygroundLogger + 383
frame #13: 0x000000010cbde62d PlaygroundLogger`___lldb_unnamed_symbol284$$PlaygroundLogger + 1357
frame #14: 0x000000010cbdcd1a PlaygroundLogger`___lldb_unnamed_symbol270$$PlaygroundLogger + 746
frame #15: 0x000000010cbde62d PlaygroundLogger`___lldb_unnamed_symbol284$$PlaygroundLogger + 1357
frame #16: 0x000000010cbdbc84 PlaygroundLogger`___lldb_unnamed_symbol258$$PlaygroundLogger + 7460
frame #17: 0x000000010cbd5752 PlaygroundLogger`___lldb_unnamed_symbol179$$PlaygroundLogger + 114
frame #18: 0x000000010cbd78e8 PlaygroundLogger`playground_log_hidden + 264
frame #19: 0x000000010d1e9427 $__lldb_expr10`main at Oscillator.xcplaygroundpage:16
frame #20: 0x0000000108f881a0 com.apple.dt.Xcode.PlaygroundStub-macosx
frame #21: 0x00007fff3643bf8c CoreFoundation`__invoking___ + 140
frame #22: 0x00007fff3643be5f CoreFoundation`-[NSInvocation invoke] + 311
frame #23: 0x00007fff3649d53d CoreFoundation`-[NSInvocation invokeWithTarget:] + 56
frame #24: 0x00007fff5f53cbf5 ViewBridge`__68-[NSVB_ViewServiceImplicitAnimationDecodingProxy forwardInvocation:]_block_invoke_2 + 46
frame #25: 0x00007fff5f501ec6 ViewBridge`-[NSViewServiceMarshal withHostWindowFrameAnimationInProgress:perform:] + 53
frame #26: 0x00007fff5f53cbbe ViewBridge`__68-[NSVB_ViewServiceImplicitAnimationDecodingProxy forwardInvocation:]_block_invoke + 113
frame #27: 0x00007fff33a19731 AppKit`+[NSAnimationContext runAnimationGroup:] + 55
frame #28: 0x00007fff33a196e7 AppKit`+[NSAnimationContext runAnimationGroup:completionHandler:] + 82
frame #29: 0x00007fff5f55f154 ViewBridge`runAnimationGroup + 295
frame #30: 0x00007fff5f53c695 ViewBridge`+[NSVB_View _animateWithAttributes:animations:completion:] + 490
frame #31: 0x00007fff5f53cb28 ViewBridge`-[NSVB_ViewServiceImplicitAnimationDecodingProxy forwardInvocation:] + 206
frame #32: 0x00007fff3648580e CoreFoundation`___forwarding___ + 780
frame #33: 0x00007fff36485478 CoreFoundation`__forwarding_prep_0___ + 120
frame #34: 0x00007fff3643bf8c CoreFoundation`__invoking___ + 140
frame #35: 0x00007fff3643be5f CoreFoundation`-[NSInvocation invoke] + 311
frame #36: 0x00007fff3649d53d CoreFoundation`-[NSInvocation invokeWithTarget:] + 56
frame #37: 0x00007fff5f504973 ViewBridge`-[NSVB_QueueingProxy forwardInvocation:] + 324
frame #38: 0x00007fff3648580e CoreFoundation`___forwarding___ + 780
frame #39: 0x00007fff36485478 CoreFoundation`__forwarding_prep_0___ + 120
frame #40: 0x00007fff3643bf8c CoreFoundation`__invoking___ + 140
frame #41: 0x00007fff3643be5f CoreFoundation`-[NSInvocation invoke] + 311
frame #42: 0x00007fff3649d53d CoreFoundation`-[NSInvocation invokeWithTarget:] + 56
frame #43: 0x00007fff3648580e CoreFoundation`___forwarding___ + 780
frame #44: 0x00007fff36485478 CoreFoundation`__forwarding_prep_0___ + 120
frame #45: 0x00007fff3643bf8c CoreFoundation`__invoking___ + 140
frame #46: 0x00007fff3643be5f CoreFoundation`-[NSInvocation invoke] + 311
frame #47: 0x00007fff5f4d16cd ViewBridge`__deferNSXPCInvocationOntoMainThread_block_invoke + 237
frame #48: 0x00007fff5f4c6af3 ViewBridge`__wrapBlockWithVoucher_block_invoke + 37
frame #49: 0x00007fff5f4c68a4 ViewBridge`__deferBlockOntoMainThread_block_invoke_2 + 553
frame #50: 0x00007fff36469ca7 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
frame #51: 0x00007fff3642cced CoreFoundation`__CFRunLoopDoBlocks + 395
frame #52: 0x00007fff3642c3eb CoreFoundation`__CFRunLoopRun + 1204
frame #53: 0x00007fff3642bce4 CoreFoundation`CFRunLoopRunSpecific + 463
frame #54: 0x00007fff356c5895 HIToolbox`RunCurrentEventLoopInMode + 293
frame #55: 0x00007fff356c55cb HIToolbox`ReceiveNextEventCommon + 618
frame #56: 0x00007fff356c5348 HIToolbox`_BlockUntilNextEventMatchingListInModeWithFilter + 64
frame #57: 0x00007fff3398295b AppKit`_DPSNextEvent + 997
frame #58: 0x00007fff339816fa AppKit`-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1362
frame #59: 0x00007fff5f4cf226 ViewBridge`-[NSViewServiceApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 92
frame #60: 0x00007fff3397b75d AppKit`-[NSApplication run] + 699
frame #61: 0x00007fff3396ae97 AppKit`NSApplicationMain + 780
frame #62: 0x00007fff636fbf1f libxpc.dylib`_xpc_objc_main + 612
frame #63: 0x00007fff636fb9e5 libxpc.dylib`xpc_main + 433
frame #64: 0x00007fff5f4c0a76 ViewBridge`-[NSXPCSharedListener resume] + 16
frame #65: 0x00007fff5f4c9a03 ViewBridge`NSViewServiceApplicationMain + 2877
frame #66: 0x0000000108f881ca com.apple.dt.Xcode.PlaygroundStub-macosx`main + 42
frame #67: 0x00007fff634c5085 libdyld.dylib`start + 1
答案 0 :(得分:2)
此代码依赖于_Self
,我认为这不是已记录的行为,并且可能并非在所有用法中都是可靠的。我相信这段代码到处都使用_Self
,这意味着要使用type(of: self)
。