travisjeffery / ClangFormat-Xcode

Xcode plug-in to to use clang-format from in Xcode and consistently format your code with Clang
https://twitter.com/travisjeffery
MIT License
2.89k stars 287 forks source link

Occasional crash on save with all text selected #6

Closed kreeger closed 10 years ago

kreeger commented 10 years ago

I've had a second crash now using this plugin when I've had all the text in my current file selected (⌘A) and I've saved my Objective-C implementation file (⌘S). It doesn't happen every time, but it definitely happens sometimes. And I'm using Format on Save, with a custom local format file. I'll post more information here as I get it.

Here's the relevant bit from the top of my crash log. I think I can see roughly where in the backtrace it's happening.

Process:         Xcode [86062]
Path:            /Applications/Xcode.app/Contents/MacOS/Xcode
Identifier:      com.apple.dt.Xcode
Version:         5.0.2 (3335.32)
Build Info:      IDEApplication-3335032000000000~4
App Item ID:     497799835
App External ID: 106632651
Code Type:       X86-64 (Native)
Parent Process:  launchd [281]
Responsible:     Xcode [86062]
User ID:         501

PlugIn Path:       /Users/USER/Library/Application Support/Developer/*/ClangFormat
PlugIn Identifier: com.travisjeffery.ClangFormat
PlugIn Version:    1.0 (1)

Date/Time:       2014-01-17 11:51:17.388 -0600
OS Version:      Mac OS X 10.9.1 (13B3116)
Report Version:  11
Anonymous UUID:  C2C45827-B501-3F46-1486-D5BE4E0284EA

Sleep/Wake UUID: 3A28DA5D-A700-4708-BA5F-39E6D47A50C3

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

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000

Application Specific Information:
ProductBuildVersion: 5A3005
ASSERTION FAILURE in /SourceCache/DVTKit/DVTKit-3553/Framework/Classes/TextCompletion/DVTCompletingTextView.m:1335
Details:  Attempt to select an invalid range of text: {18446744073709551610, 0}. Text length: 2026. (Please file a Radar. OK to Continue from here.)
Object:   <DVTSourceTextView: 0x7ff9178a8810>
Method:   -setSelectedRange:
Thread:   <NSThread: 0x7ff910e15130>{name = (null), num = 1}
Hints:   None
Backtrace:
  0  0x0000000108ed8ea8 -[IDEAssertionHandler handleFailureInMethod:object:fileName:lineNumber:messageFormat:arguments:] (in IDEKit)
  1  0x0000000107c677a5 _DVTAssertionHandler (in DVTFoundation)
  2  0x0000000107c67ad4 _DVTAssertionFailureHandler (in DVTFoundation)
  3  0x000000010818f1df -[DVTCompletingTextView setSelectedRange:] (in DVTKit)
  4  0x00000001081b86a4 -[DVTSourceTextView setSelectedRange:] (in DVTKit)
  5  0x00007fff9348b07b _NSSetRangeValueAndNotify (in Foundation)
  6  0x00000001103b343e -[TRVSFormatter formatDocument:] at /Users/ben/Library/Application Support/Alcatraz/Plug-ins/ClangFormat/ClangFormat/TRVSFormatter.m:76 (in ClangFormat)
  7  0x00000001103b4313 -[NSDocument(TRVSClangFormat) trvs_saveDocumentWithDelegate:didSaveSelector:contextInfo:] at /Users/ben/Library/Application Support/Alcatraz/Plug-ins/ClangFormat/ClangFormat/NSDocument+TRVSClangFormat.m:18 (in ClangFormat)
  8  0x0000000108f0a90b __34-[IDEEditorDocument saveDocument:]_block_invoke (in IDEKit)
  9  0x0000000108d94494 -[IDEEditorDocument _unlockIfNeededCompletionBlock:] (in IDEKit)
 10  0x0000000108d97c3c -[IDEEditorDocument saveDocument:] (in IDEKit)
 11  0x00007fff9007d3d0 -[NSApplication sendAction:to:from:] (in AppKit)
 12  0x0000000108348aff __37-[DVTApplication sendAction:to:from:]_block_invoke (in DVTKit)
 13  0x000000010817a544 -[DVTApplication sendAction:to:from:] (in DVTKit)
 14  0x00007fff90098348 -[NSMenuItem _corePerformAction] (in AppKit)
 15  0x00007fff90098084 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] (in AppKit)
 16  0x00007fff900971fc -[NSMenu performKeyEquivalent:] (in AppKit)
 17  0x00007fff90093a61 -[NSApplication _handleKeyEquivalent:] (in AppKit)
 18  0x00007fff90002c3c -[NSApplication sendEvent:] (in AppKit)
 19  0x0000000108cdb83b -[IDEApplication sendEvent:] (in IDEKit)
 20  0x00007fff8fe52a29 -[NSApplication run] (in AppKit)
 21  0x00007fff8fe3d803 NSApplicationMain (in AppKit)
 22  0x00007fff975945fd start (in libdyld.dylib)
 23  0x0000000000000001

Performing @selector(ide_saveDocument:) from sender NSMenuItem 0x7ff913550e90
abort() called

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib          0x00007fff8c236866 __pthread_kill + 10
1   libsystem_pthread.dylib         0x00007fff8c15035c pthread_kill + 92
2   libsystem_c.dylib               0x00007fff9540dbba abort + 125
3   com.apple.dt.IDEKit             0x0000000108ed87af +[IDEAssertionHandler _handleAssertionWithLogString:reason:] + 775
4   com.apple.dt.IDEKit             0x0000000108ed900e -[IDEAssertionHandler handleFailureInMethod:object:fileName:lineNumber:messageFormat:arguments:] + 1117
5   com.apple.dt.DVTFoundation      0x0000000107c677a5 _DVTAssertionHandler + 421
6   com.apple.dt.DVTFoundation      0x0000000107c67ad4 _DVTAssertionFailureHandler + 322
7   com.apple.dt.DVTKit             0x000000010818f1df -[DVTCompletingTextView setSelectedRange:] + 181
8   com.apple.dt.DVTKit             0x00000001081b86a4 -[DVTSourceTextView setSelectedRange:] + 52
9   com.apple.Foundation            0x00007fff9348b07b _NSSetRangeValueAndNotify + 277
10  com.travisjeffery.ClangFormat   0x00000001103b343e -[TRVSFormatter formatDocument:] + 463 (TRVSFormatter.m:92)
11  com.travisjeffery.ClangFormat   0x00000001103b4313 -[NSDocument(TRVSClangFormat) trvs_saveDocumentWithDelegate:didSaveSelector:contextInfo:] + 107 (NSDocument+TRVSClangFormat.m:22)
12  com.apple.dt.IDEKit             0x0000000108f0a90b __34-[IDEEditorDocument saveDocument:]_block_invoke + 56
13  com.apple.dt.IDEKit             0x0000000108d94494 -[IDEEditorDocument _unlockIfNeededCompletionBlock:] + 638
14  com.apple.dt.IDEKit             0x0000000108d97c3c -[IDEEditorDocument saveDocument:] + 674
15  com.apple.AppKit                0x00007fff9007d3d0 -[NSApplication sendAction:to:from:] + 327
16  com.apple.dt.DVTKit             0x0000000108348aff __37-[DVTApplication sendAction:to:from:]_block_invoke + 351
17  com.apple.dt.DVTKit             0x000000010817a544 -[DVTApplication sendAction:to:from:] + 226
18  com.apple.AppKit                0x00007fff90098348 -[NSMenuItem _corePerformAction] + 394
19  com.apple.AppKit                0x00007fff90098084 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 117
20  com.apple.AppKit                0x00007fff900971fc -[NSMenu performKeyEquivalent:] + 289
21  com.apple.AppKit                0x00007fff90093a61 -[NSApplication _handleKeyEquivalent:] + 822
22  com.apple.AppKit                0x00007fff90002c3c -[NSApplication sendEvent:] + 3293
23  com.apple.dt.IDEKit             0x0000000108cdb83b -[IDEApplication sendEvent:] + 444
24  com.apple.AppKit                0x00007fff8fe52a29 -[NSApplication run] + 646
25  com.apple.AppKit                0x00007fff8fe3d803 NSApplicationMain + 940
26  libdyld.dylib                   0x00007fff975945fd start + 1

Here's my .clang-format file for reference.

AccessModifierOffset: 1
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: true
BinPackParameters: false
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: false
ColumnLimit: 120
ConstructorInitializerAllOnOneLineOrOnePerLine: true
IndentCaseLabels: true
IndentWidth: 4
Language: Cpp
MaxEmptyLinesToKeep: 1
ObjCSpaceBeforeProtocolList: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Always
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
Standard: Cpp11
TabWidth: 4
UseTab: Never
travisjeffery commented 10 years ago

This should do it: https://github.com/travisjeffery/ClangFormat-Xcode/issues/5#ref-commit-e5ee9ff

Thanks for including the log.

kreeger commented 10 years ago

If there was an emoji for shaking my head in a double-take, I'd use it. Thanks for the quick turnaround!