Open brynbellomy opened 12 years ago
Are you using the pre-compiled package or directly from source?
At the moment I'm compiling from source- I've seen the crash on both repeatedly for a couple of months at least but have (obviously, I suppose) only been able to try my fix on the from-source version. Still no crashes and I've been writing and scrapping unit tests all damn day...
On Jul 21, 2012, at 4:22 PM, Patrick reply@reply.github.com wrote:
Are you using the pre-compiled package or directly from source?
Reply to this email directly or view it on GitHub: https://github.com/JugglerShu/XVim/issues/251#issuecomment-7156324
From a cursory look at that section it seems like that shouldn't have any negative side effects. I'd do a pull request and let Shu decide if it cuts it.
I have more info on this crash now and a different (tentative) recommendation for a fix.
I experienced the crash again today when using Xcode's Cmd+/ shortcut to uncomment a few lines at the very end of a buffer. The assertion failure is identical to the one mentioned above (DVTCompletingTextView.m line 1116), but the backtrace is slightly different. I've included a portion of the crash log below so you can check it out.
It seems that both this crash and the one in my original post on this issue are caused by calling -[XVimSourceView setSelectedRange:]
with an NSRange argument that has a location
property that is past the end of the active buffer. Even though the NSRange's length is 0 (thereby just unselecting any selected text), it seems that the view is also trying to set the current cursor position using the location
property.
Side note: I've noticed when removing multi-line blocks of text in Visual mode that the cursor position is incorrect after the text has been removed. Whichever portion of the code is calculating the new position of the cursor after removing text is not accounting for the lines of text that were just removed. For example, if I remove, say, 7 lines, the cursor is 7 lines farther down in the buffer than it should be. I think that this might actually be the root cause of both of the crashes I've reported in this issue. Fixing this might solve both crashes as well as the incorrect cursor positioning problem all at the same time.
Anyway, this is my current fix for both crashes I've reported in this issue. Let me know what you think about what I'm doing here, or if you have any refactoring requests. The code simply checks to see if the range
argument exceeds the length of the active buffer, and if so, trims it to fit (in the most extreme case, it creates a 0-length range whose location is the very last character in the buffer).
diff --git a/XVim/XVimSourceView.m b/XVim/XVimSourceView.m
index 65fc546..1dc99ea 100644
--- a/XVim/XVimSourceView.m
+++ b/XVim/XVimSourceView.m
@@ -373,6 +373,12 @@
- (void)setSelectedRange:(NSRange)range
{
+ if ((range.location + range.length) > [self string].length) {
+ NSUInteger newRangeLoc = MIN(range.location, [self string].length);
+ NSUInteger newRangeLen = MIN(range.length, range.location - [self string].length);
+ range = NSMakeRange(newRangeLoc, newRangeLen);
+ }
+
[_view setSelectedRange:range];
}
Here's the crash log with the backtrace:
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Application Specific Information:
ProductBuildVersion: 4E3002
ASSERTION FAILURE in /SourceCache/DVTKit/DVTKit-1176/Framework/Classes/TextCompletion/DVTCompletingTextView.m:1116
Details: Attempt to select an invalid range of text: {6855, 0}. Text length: 6847. (Please file a Radar. OK to Continue from here.)
Object: <DVTSourceTextView: 0x40a27b580>
Method: -setSelectedRange:
Thread: <NSThread: 0x40010a220>{name = (null), num = 1}
Hints: None
Backtrace:
0 0x000000010c0eeb9f -[IDEAssertionHandler handleFailureInMethod:object:fileName:lineNumber:messageFormat:arguments:] (in IDEKit)
1 0x000000010b59f5d5 _DVTAssertionFailureHandler (in DVTFoundation)
2 0x000000010b82bcb0 -[DVTCompletingTextView setSelectedRange:] (in DVTKit)
3 0x000000010b8553a8 -[DVTSourceTextView setSelectedRange:] (in DVTKit)
4 0x0000000114402e83 -[DVTSourceTextViewHook setSelectedRange:] at /src/objective-c/XVim/XVim/DVTSourceTextViewHook.m:72 (in XVim)
5 0x000000011441a465 -[XVimSourceView setSelectedRange:] at /src/objective-c/XVim/XVim/XVimSourceView.m:374 (in XVim)
6 0x00000001143f69ab -[XVimVisualEvaluator ESC:] at /src/objective-c/XVim/XVim/XVimVisualEvaluator.m:426 (in XVim)
7 0x00007fff8bcac70d -[NSObject performSelector:withObject:] (in CoreFoundation)
8 0x00000001143ee7ed -[XVimEvaluator eval:inWindow:] at /src/objective-c/XVim/XVim/XVimEvaluator.m:54 (in XVim)
9 0x000000011440420c -[XVimNumericEvaluator eval:inWindow:] at /src/objective-c/XVim/XVim/XVimNumericEvaluator.m:19 (in XVim)
10 0x00000001143f4da0 -[XVimVisualEvaluator eval:inWindow:] at /src/objective-c/XVim/XVim/XVimVisualEvaluator.m:148 (in XVim)
11 0x000000011441c6af -[XVimWindow handleKeyStroke:] at /src/objective-c/XVim/XVim/XVimWindow.m:130 (in XVim)
12 0x000000011441c495 -[XVimWindow handleKeyEvent:] at /src/objective-c/XVim/XVim/XVimWindow.m:103 (in XVim)
13 0x00000001144031d5 -[DVTSourceTextViewHook keyDown:] at /src/objective-c/XVim/XVim/DVTSourceTextViewHook.m:90 (in XVim)
14 0x00007fff900e97ac -[NSWindow sendEvent:] (in AppKit)
15 0x00007fff90082a55 -[NSApplication sendEvent:] (in AppKit)
16 0x000000010bf6add1 -[IDEApplication sendEvent:] (in IDEKit)
17 0x00007fff900190c6 -[NSApplication run] (in AppKit)
18 0x00007fff90295244 NSApplicationMain (in AppKit)
19 0x000000010b515eec (in Xcode)
20 0x0000000000000002
objc[22637]: garbage collection is ON
abort() called
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fff8a388ce2 __pthread_kill + 10
1 libsystem_c.dylib 0x00007fff8a4e77d2 pthread_kill + 95
2 libsystem_c.dylib 0x00007fff8a4d8a7a abort + 143
3 com.apple.dt.IDEKit 0x000000010c0ee60e +[IDEAssertionHandler _handleAssertionWithLogString:] + 506
4 com.apple.dt.DVTFoundation 0x000000010b59f5d5 _DVTAssertionFailureHandler + 128
5 com.apple.dt.DVTKit 0x000000010b82bcb0 -[DVTCompletingTextView setSelectedRange:] + 244
6 com.apple.dt.DVTKit 0x000000010b8553a8 -[DVTSourceTextView setSelectedRange:] + 52
7 net.JugglerShu.XVim 0x0000000114402e83 -[DVTSourceTextViewHook setSelectedRange:] + 67 (DVTSourceTextViewHook.m:76)
8 net.JugglerShu.XVim 0x000000011441a465 -[XVimSourceView setSelectedRange:] + 69 (XVimSourceView.m:377)
9 net.JugglerShu.XVim 0x00000001143f69ab -[XVimVisualEvaluator ESC:] + 155 (XVimVisualEvaluator.m:428)
10 com.apple.CoreFoundation 0x00007fff8bcac70d -[NSObject performSelector:withObject:] + 61
11 net.JugglerShu.XVim 0x00000001143ee7ed -[XVimEvaluator eval:inWindow:] + 189 (XVimEvaluator.m:64)
12 net.JugglerShu.XVim 0x000000011440420c -[XVimNumericEvaluator eval:inWindow:] + 636 (XVimNumericEvaluator.m:57)
13 net.JugglerShu.XVim 0x00000001143f4da0 -[XVimVisualEvaluator eval:inWindow:] + 352 (XVimVisualEvaluator.m:154)
14 net.JugglerShu.XVim 0x000000011441c6af -[XVimWindow handleKeyStroke:] + 111 (XVimWindow.m:134)
15 net.JugglerShu.XVim 0x000000011441c495 -[XVimWindow handleKeyEvent:] + 549 (XVimWindow.m:116)
16 net.JugglerShu.XVim 0x00000001144031d5 -[DVTSourceTextViewHook keyDown:] + 629 (DVTSourceTextViewHook.m:112)
17 com.apple.AppKit 0x00007fff900e97ac -[NSWindow sendEvent:] + 7430
18 com.apple.AppKit 0x00007fff90082a55 -[NSApplication sendEvent:] + 5593
19 com.apple.dt.IDEKit 0x000000010bf6add1 -[IDEApplication sendEvent:] + 366
20 com.apple.AppKit 0x00007fff900190c6 -[NSApplication run] + 555
21 com.apple.AppKit 0x00007fff90295244 NSApplicationMain + 867
22 com.apple.dt.Xcode 0x000000010b515eec 0x10b515000 + 3820
Your analysis is pretty sound. I would think that adding a logging statement when an exceptional situation occurs to this would help the situations that cause this type of error to be debugged a little bit quicker. I think that it is also probably preferable to not crash whenever possible even though this is alpha software and that a crash might help find the larger bug.
I will take a look at the invalid cursor position update as well because that is the cause of a few reported bugs in visual mode so far. Thanks for the detailed bug report.
So I am trying to recreate this error and I am having trouble. Can you detail the steps that make it happen? I tried selecting the text via the mouse both forward selection and reverse selection. Is there anything in your source code that is out of the ordinary? Any sample file that you can reproduce the error 100%?
Generally I see this when I select a large amount of text near the end of the file using Visual Line mode and then hit 'd' or 'x' (although what I mean by "large" is actually proportional to the proximity of the selection to the end of the file I think). I never use the mouse for selecting text, so try it with the keyboard just to be sure.
I've noticed that if I'm in Insert mode and I do the exact same thing, the crash never occurs. And FWIW, it's very easy to accidentally break out of Insert mode into Visual mode -- you have to make sure you ONLY use the arrow keys to move the cursor while selecting, no mouse or anything else. So I guess different methods are being invoked in each respective mode.
As far as reproducing the bug, try this: enter Visual Line mode at the very end of a file and then move up about 30-40 lines using the 'k' key so that you have all 30-40 lines selected. Then hit 'd' or 'x'. That would pretty much always do it for me.
When you have a chance, post a note on this issue thread once you've had time to try what I'm suggesting here. I'm about to get on a plane, but once I'm back on solid ground I'd be happy to offer more help with reproducing the bug.
Oh, and re: your question, there was nothing unusual about the source files... just standard Objective-C.
Just experienced the first crash since I implemented the fix I posted above. Incidentally, I upgraded to Xcode 4.4 last night. Not sure if that's related, but here's the stack trace. I'll work on a fix in a little while.
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Application Specific Information:
objc[72904]: garbage collection is ON
ProductBuildVersion: 4F155i
UNCAUGHT EXCEPTION (NSRangeException): -[__NSCFString characterAtIndex:]: Range or index out of bounds
UserInfo: (null)
Hints: None
Backtrace:
0 0x00007fff8bcbcf3a __exceptionPreprocess (in CoreFoundation)
1 0x00007fff8ceadd5e objc_exception_throw (in libobjc.A.dylib)
2 0x00007fff8bcbcd8a +[NSException raise:format:arguments:] (in CoreFoundation)
3 0x00007fff8bcbcd14 +[NSException raise:format:] (in CoreFoundation)
4 0x00007fff8bc7a7ae -[__NSCFString characterAtIndex:] (in CoreFoundation)
5 0x000000011851779c -[XVimSourceView scrollTo:] at /src/objective-c/XVim/XVim/XVimSourceView.m:165 (in XVim)
6 0x00000001184f402c -[XVimVisualEvaluator updateSelectionInWindow:] at /src/objective-c/XVim/XVim/XVimVisualEvaluator.m:160 (in XVim)
7 0x00000001184f366e -[XVimVisualEvaluator defaultNextEvaluatorInWindow:] at /src/objective-c/XVim/XVim/XVimVisualEvaluator.m:71 (in XVim)
8 0x00000001184ed83b -[XVimEvaluator eval:inWindow:] at /src/objective-c/XVim/XVim/XVimEvaluator.m:54 (in XVim)
9 0x000000011850319b -[XVimNumericEvaluator eval:inWindow:] at /src/objective-c/XVim/XVim/XVimNumericEvaluator.m:19 (in XVim)
10 0x00000001184f3d50 -[XVimVisualEvaluator eval:inWindow:] at /src/objective-c/XVim/XVim/XVimVisualEvaluator.m:148 (in XVim)
11 0x000000011851b71f -[XVimWindow handleKeyStroke:] at /src/objective-c/XVim/XVim/XVimWindow.m:130 (in XVim)
12 0x000000011851b505 -[XVimWindow handleKeyEvent:] at /src/objective-c/XVim/XVim/XVimWindow.m:103 (in XVim)
13 0x0000000118502145 -[DVTSourceTextViewHook keyDown:] at /src/objective-c/XVim/XVim/DVTSourceTextViewHook.m:90 (in XVim)
14 0x00007fff900e97ac -[NSWindow sendEvent:] (in AppKit)
15 0x00007fff90082a55 -[NSApplication sendEvent:] (in AppKit)
16 0x0000000110816944 -[IDEApplication sendEvent:] (in IDEKit)
17 0x00007fff900190c6 -[NSApplication run] (in AppKit)
18 0x00007fff90295244 NSApplicationMain (in AppKit)
19 0x000000010fc3be2c (in Xcode)
Another one on Xcode 4.4 ... I realize these stack traces don't all show failures in the same place, but I have this hunch that all of these errors are emanating from the same place, given that they all have to do with out-of-bounds errors with the main text editing view. Like I said before, I'll dig into this myself when I get a chance.
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Application Specific Information:
objc[24982]: garbage collection is ON
ProductBuildVersion: 4F155i
UNCAUGHT EXCEPTION (NSInternalInconsistencyException): index can not be invalid cursor position
UserInfo: (null)
Hints: None
Backtrace:
0 0x00007fff8bcbcf3a __exceptionPreprocess (in CoreFoundation)
1 0x00007fff8ceadd5e objc_exception_throw (in libobjc.A.dylib)
2 0x00007fff8bcbcd8a +[NSException raise:format:arguments:] (in CoreFoundation)
3 0x00007fff8adf571f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] (in Foundation)
4 0x00000001159e425f -[XVimSourceView(Vim) endOfLine:] at /src/objective-c/XVim/XVim/XVimSourceView+Vim.m:380 (in XVim)
5 0x00000001159b48c8 -[XVimVisualEvaluator becameHandlerInWindow:] at /src/objective-c/XVim/XVim/XVimVisualEvaluator.m:83 (in XVim)
6 0x00000001159dc247 -[XVimWindow setEvaluator:] at /src/objective-c/XVim/XVim/XVimWindow.m:66 (in XVim)
7 0x00000001159dc7d3 -[XVimWindow handleKeyStroke:] at /src/objective-c/XVim/XVim/XVimWindow.m:130 (in XVim)
8 0x00000001159dc505 -[XVimWindow handleKeyEvent:] at /src/objective-c/XVim/XVim/XVimWindow.m:103 (in XVim)
9 0x00000001159c3145 -[DVTSourceTextViewHook keyDown:] at /src/objective-c/XVim/XVim/DVTSourceTextViewHook.m:90 (in XVim)
10 0x00007fff900e97ac -[NSWindow sendEvent:] (in AppKit)
11 0x00007fff90082a55 -[NSApplication sendEvent:] (in AppKit)
12 0x000000010da23944 -[IDEApplication sendEvent:] (in IDEKit)
13 0x00007fff900190c6 -[NSApplication run] (in AppKit)
14 0x00007fff90295244 NSApplicationMain (in AppKit)
15 0x000000010ce46e2c (in Xcode)
abort() called
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fff8a388ce2 __pthread_kill + 10
1 libsystem_c.dylib 0x00007fff8a4e77d2 pthread_kill + 95
2 libsystem_c.dylib 0x00007fff8a4d8a7a abort + 143
3 com.apple.dt.IDEKit 0x000000010dbaf2a5 +[IDEAssertionHandler _handleAssertionWithLogString:] + 506
4 com.apple.dt.IDEKit 0x000000010dbaff20 -[IDEAssertionHandler handleUncaughtException:] + 603
5 com.apple.AppKit 0x00007fff90019176 -[NSApplication run] + 731
6 com.apple.AppKit 0x00007fff90295244 NSApplicationMain + 867
7 com.apple.dt.Xcode 0x000000010ce46e2c 0x10ce45000 + 7724
I have not been able to replicate this bug on Xcode 4.3 no matter how hard I try to crash it so it's probably because of version 4.4. I wish we had unit tests that would be able to catch bugs like this in a more automated fashion.
Sorry that I have not been able to commit this project since 2 or 3 mohth ago. I want to continue this project but currently I have a lot of things to do... I hope I can restart this project in Aug...
Another one, this time on a fresh install of Xcode 4.5DP4 on a fresh install of Mountain Lion. Same failed assertion...
BTW, none of my previous fixes are compiled into the XVim plugin I'm using.
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Application Specific Information:
ProductBuildVersion: 4G144l
ASSERTION FAILURE in /SourceCache/DVTKit/DVTKit-1825/Framework/Classes/TextCompletion/DVTCompletingTextView.m:1215
Details: Attempt to select an invalid range of text: {17392, 0}. Text length: 17014. (Please file a Radar. OK to Continue from here.)
Object: <DVTSourceTextView: 0x4045ec240>
Method: -setSelectedRange:
Thread: <NSThread: 0x40030a260>{name = (null), num = 1}
Hints: None
Backtrace:
0 0x000000010eb3483f -[IDEAssertionHandler handleFailureInMethod:object:fileName:lineNumber:messageFormat:arguments:] (in IDEKit)
1 0x000000010ddfbbf5 _DVTAssertionFailureHandler (in DVTFoundation)
2 0x000000010e1b700c -[DVTCompletingTextView setSelectedRange:] (in DVTKit)
3 0x000000010e1dfbe8 -[DVTSourceTextView setSelectedRange:] (in DVTKit)
4 0x00000001162e2e53 -[DVTSourceTextViewHook setSelectedRange:] at /src-temp/XVim/XVim/DVTSourceTextViewHook.m:72 (in XVim)
5 0x00000001162fa435 -[XVimSourceView setSelectedRange:] at /src-temp/XVim/XVim/XVimSourceView.m:374 (in XVim)
6 0x00000001162d4d2b -[XVimVisualEvaluator eval:inWindow:] at /src-temp/XVim/XVim/XVimVisualEvaluator.m:148 (in XVim)
7 0x00000001162fc67f -[XVimWindow handleKeyStroke:] at /src-temp/XVim/XVim/XVimWindow.m:130 (in XVim)
8 0x00000001162fc465 -[XVimWindow handleKeyEvent:] at /src-temp/XVim/XVim/XVimWindow.m:103 (in XVim)
9 0x00000001162e31a5 -[DVTSourceTextViewHook keyDown:] at /src-temp/XVim/XVim/DVTSourceTextViewHook.m:90 (in XVim)
10 0x00007fff82ea28e0 -[NSWindow sendEvent:] (in AppKit)
11 0x00007fff82e9df04 -[NSApplication sendEvent:] (in AppKit)
12 0x000000010e9a8874 -[IDEApplication sendEvent:] (in IDEKit)
13 0x00007fff82db3c7a -[NSApplication run] (in AppKit)
14 0x00007fff82d58656 NSApplicationMain (in AppKit)
15 0x000000010dd6fd17 (in Xcode)
16 0x000000010dd6fca8 (in Xcode)
17 0x0000000000000002
objc[14985]: garbage collection is ON
abort() called
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fff88620212 __pthread_kill + 10
1 libsystem_c.dylib 0x00007fff84ad9b34 pthread_kill + 90
2 libsystem_c.dylib 0x00007fff84b1ddfa abort + 143
3 com.apple.dt.IDEKit 0x000000010eb342a5 +[IDEAssertionHandler _handleAssertionWithLogString:] + 506
4 com.apple.dt.DVTFoundation 0x000000010ddfbbf5 _DVTAssertionFailureHandler + 128
5 com.apple.dt.DVTKit 0x000000010e1b700c -[DVTCompletingTextView setSelectedRange:] + 254
6 com.apple.dt.DVTKit 0x000000010e1dfbe8 -[DVTSourceTextView setSelectedRange:] + 52
7 net.JugglerShu.XVim 0x00000001162e2e53 -[DVTSourceTextViewHook setSelectedRange:] + 67 (DVTSourceTextViewHook.m:76)
8 net.JugglerShu.XVim 0x00000001162fa435 -[XVimSourceView setSelectedRange:] + 69 (XVimSourceView.m:377)
9 net.JugglerShu.XVim 0x00000001162d4d2b -[XVimVisualEvaluator eval:inWindow:] + 155 (XVimVisualEvaluator.m:151)
10 net.JugglerShu.XVim 0x00000001162fc67f -[XVimWindow handleKeyStroke:] + 111 (XVimWindow.m:134)
11 net.JugglerShu.XVim 0x00000001162fc465 -[XVimWindow handleKeyEvent:] + 549 (XVimWindow.m:116)
12 net.JugglerShu.XVim 0x00000001162e31a5 -[DVTSourceTextViewHook keyDown:] + 629 (DVTSourceTextViewHook.m:112)
13 com.apple.AppKit 0x00007fff82ea28e0 -[NSWindow sendEvent:] + 9687
14 com.apple.AppKit 0x00007fff82e9df04 -[NSApplication sendEvent:] + 5761
15 com.apple.dt.IDEKit 0x000000010e9a8874 -[IDEApplication sendEvent:] + 369
16 com.apple.AppKit 0x00007fff82db3c7a -[NSApplication run] + 636
17 com.apple.AppKit 0x00007fff82d58656 NSApplicationMain + 869
18 com.apple.dt.Xcode 0x000000010dd6fd17 0x10dd6e000 + 7447
19 com.apple.dt.Xcode 0x000000010dd6fca8 0x10dd6e000 + 7336
Thanks. I have time today I'll see this problem.
Awesome! I think I made some progress determining the source of the error, but I was never able to eliminate 100% of the crashes. You can see the changes I made in this thread. Anyway, I'll continue to work on this too.
I also have difficulties to reproduce this problem. BUT this is really likely to happen I think because I remember that I fixed this kind of crashes before and there should be some cases which is not handled properly.
Even I can not find the exact problem I'll see if there is any problem especially around setSelectedRange in XVimSourceView.
I encountered something (at least) similar to the issue. I might be a few versions behind, but I thought I would leave my stack trace here. I used visual mode to select a large block of text that was commented, uncommented, then when exiting visual mode XVim crashed.
I think an easy way to reproduce this would be as follows: 1) enter any file 2) place the cursor on the very first character of the file 3) enter visual mode 4) hit gg to move to the end of the file 5) hit cmd/ to comment the selected lines (every line in the file) 6) exit visual mode --- Repeat steps 2-6, this time uncommenting 7) place the cursor back at the very first character 8) enter visual mode 9) hit gg to move to the end of the file 10) hit cmd/ to uncomment the selected lines 11) exit visual mode
At the end of the process I believe that XVim is trying to set the cursor to the range {N, 0} where N was the number of characters BEFORE the change. When I have time I will review the code posted here and see if I can help out in any way.
Process: Xcode [18406]
Path: /Applications/Xcode.app/Contents/MacOS/Xcode
Identifier: com.apple.dt.Xcode
Version: 4.5 (1839)
Build Info: IDEApplication-1839000000000000~3
Code Type: X86-64 (Native)
Parent Process: launchd [236]
User ID: 501
PlugIn Path: /Users/USER/Library/Application Support/Developer/*/XVim
PlugIn Identifier: net.JugglerShu.XVim
PlugIn Version: 1.01 (1)
Date/Time: 2013-01-15 22:57:04.217 -0800
OS Version: Mac OS X 10.8.2 (12C3012)
Report Version: 10
Interval Since Last Report: 2022135 sec
Crashes Since Last Report: 71
Per-App Interval Since Last Report: 870598 sec
Per-App Crashes Since Last Report: 11
Anonymous UUID: 055E2C61-9208-BBBD-E27D-8A84F1CCACD7
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Application Specific Information:
ProductBuildVersion: 4G182
ASSERTION FAILURE in /SourceCache/DVTKit/DVTKit-1832/Framework/Classes/TextCompletion/DVTCompletingTextView.m:1215
Details: Attempt to select an invalid range of text: {2828, 0}. Text length: 2760. (Please file a Radar. OK to Continue from here.)
Object: <DVTSourceTextView: 0x4045da0e0>
Method: -setSelectedRange:
Thread: <NSThread: 0x40030a220>{name = (null), num = 1}
Hints: None
Backtrace:
0 0x0000000101d2f7ef -[IDEAssertionHandler handleFailureInMethod:object:fileName:lineNumber:messageFormat:arguments:] (in IDEKit)
1 0x0000000100ff52a5 _DVTAssertionFailureHandler (in DVTFoundation)
2 0x00000001013aa879 -[DVTCompletingTextView setSelectedRange:] (in DVTKit)
3 0x00000001013d3468 -[DVTSourceTextView setSelectedRange:] (in DVTKit)
4 0x00000001094e1db3 -[DVTSourceTextViewHook setSelectedRange:] (in XVim)
5 0x00000001094f9805 -[XVimSourceView setSelectedRange:] (in XVim)
6 0x00000001094d37cb -[XVimVisualEvaluator eval:inWindow:] (in XVim)
7 0x00000001094fbdbf -[XVimWindow handleKeyStroke:] (in XVim)
8 0x00000001094fb852 -[XVimWindow handleKeyEvent:] (in XVim)
9 0x00000001094e2004 -[DVTSourceTextViewHook keyDown:] (in XVim)
10 0x00007fff89d05120 -[NSWindow sendEvent:] (in AppKit)
11 0x00007fff89d00744 -[NSApplication sendEvent:] (in AppKit)
12 0x0000000101ba45c4 -[IDEApplication sendEvent:] (in IDEKit)
13 0x00007fff89c162fa -[NSApplication run] (in AppKit)
14 0x00007fff89bbacb6 NSApplicationMain (in AppKit)
15 0x0000000100f6dd17 (in Xcode)
16 0x0000000100f6dca8 (in Xcode)
objc[18406]: garbage collection is ON
abort() called
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fff815de212 __pthread_kill + 10
1 libsystem_c.dylib 0x00007fff86efcaf4 pthread_kill + 90
2 libsystem_c.dylib 0x00007fff86f40dce abort + 143
3 com.apple.dt.IDEKit 0x0000000101d2f25f +[IDEAssertionHandler _handleAssertionWithLogString:] + 596
4 com.apple.dt.DVTFoundation 0x0000000100ff52a5 _DVTAssertionFailureHandler + 128
5 com.apple.dt.DVTKit 0x00000001013aa879 -[DVTCompletingTextView setSelectedRange:] + 254
6 com.apple.dt.DVTKit 0x00000001013d3468 -[DVTSourceTextView setSelectedRange:] + 52
7 net.JugglerShu.XVim 0x00000001094e1db3 -[DVTSourceTextViewHook setSelectedRange:] + 67
8 net.JugglerShu.XVim 0x00000001094f9805 -[XVimSourceView setSelectedRange:] + 69
9 net.JugglerShu.XVim 0x00000001094d37cb -[XVimVisualEvaluator eval:inWindow:] + 155
10 net.JugglerShu.XVim 0x00000001094fbdbf -[XVimWindow handleKeyStroke:] + 111
11 net.JugglerShu.XVim 0x00000001094fb852 -[XVimWindow handleKeyEvent:] + 578
12 net.JugglerShu.XVim 0x00000001094e2004 -[DVTSourceTextViewHook keyDown:] + 372
13 com.apple.AppKit 0x00007fff89d05120 -[NSWindow sendEvent:] + 9687
14 com.apple.AppKit 0x00007fff89d00744 -[NSApplication sendEvent:] + 5761
15 com.apple.dt.IDEKit 0x0000000101ba45c4 -[IDEApplication sendEvent:] + 369
16 com.apple.AppKit 0x00007fff89c162fa -[NSApplication run] + 636
17 com.apple.AppKit 0x00007fff89bbacb6 NSApplicationMain + 869
18 com.apple.dt.Xcode 0x0000000100f6dd17 0x100f6c000 + 7447
19 com.apple.dt.Xcode 0x0000000100f6dca8 0x100f6c000 + 7336
I realise this is a very old issue, but I've recently started getting this crash regularly with Xcode 7.3. Running a debug instance of xvim, it's quite clear why this happens.
You have a text range, lets say 0,2000. You select the last 50 lines, and your cursor is on line 1999. You hit d
. xvim yanks the selection, then when performing d
the cursor is now out of bounds as the end of the file is line 1950, and your cursor is on line 1999.
The exception is raised in NSTextStorage+VimOperation.m, specifically during the assert line:
- (BOOL) isEOF:(NSUInteger)index{
ASSERT_VALID_RANGE_WITH_EOF(index);
return [[self xvim_string] length] == index;
}
I think the easiest fix for this would be to position the cursor on the selection range start line when deleting. I'll have a dig round and see if I can introduce a fix.
Found a work around and submitted a Pull Request.
Didn't see an issue that reported exactly these preconditions, although I noticed a few that involved the same failed assertion (DVTCompletingTextView.m, line 1116).
The crash occurs most often when I'm in Visual mode and I remove a large block of selected text (using either
x
ord
). Definitely seems to be related to the change in the size of the buffer.For what it's worth, I opened up the Xvim source for the first time and just poked around for a minute. Came across a few lines that looked relevant and made this change, which so far has stopped this crash completely:
Of course, I don't know ANYTHING about the code whatsoever, so I don't dare issue a pull request yet ... maybe y'all can just glance over it and see what you think. This crash happens to me like 5-10 times every session. Running Xcode 4.3 and 4.5.
Crash report follows: