From: Marc <ma...@da...> - 2008-09-25 19:31:12
|
Am 25.09.2008 um 20:46 schrieb Marc: > Hi folks, > after updating to Mac OS X 10.5.2 I experienced a huge problem with > iTerm on my MacBook Pro (but not my iMac at work): after starting up > iTerm hung up. The UI rendered, but upon trying to render the > session nothing happened. > > I then got the latest CVS version, but with the same problem. But in > XCode I saw an error message regarding a deadlock in NSLock: > > Thu Sep 25 20:34:52 neotokyo.local iTerm[14091] <Warning>: > CGSResolveShmemReference : reference offset (65296) exceeds bounds > (32768) on shmem obj 0x2f69 > 2008-09-25 20:34:52.793 iTerm[14091:10b] Error (1000) creating > CGSWindow > 2008-09-25 20:34:52.806 iTerm[14091:10b] *** -[NSLock lock]: > deadlock (<NSLock: 0xfcccc0> '(null)') > 2008-09-25 20:34:52.806 iTerm[14091:10b] *** Break on _NSLockError() > to debug. > > But it turned out that the deadlock was only the symptom, not the > cause. After some googling, it seems that the "Error (1000) ..." > stuff is a bug in Mac OS X 10.5.x. It's running inside code that is > started with a [VT100Screen tryLock]. Because of the exception, the > corresponding [VT100Screen releaseLock] is never called. Then the > same thread later tries to run [VT100Screen acquireLock] and there > you have your deadlock. > > I traced the exception to PTYTextView::_renderChar (how do you write > that in Objective-C syntax ?), more precisely to [image lockFocus]. > > The attached patch works around the bug by packing the [image > lockFocus] into a @try @catch block. It retries the lockFocus up to > five times. If that still does not work then the exception is > rethrown. That fixes the hang problem for me. > > Bye, > Marc > > > -- > Marc Haisenko > ma...@da... Damn it, why do my patches get stripped ? So, here it is inline... Index: PTYTextView.m =================================================================== RCS file: /cvsroot/iterm/iTerm/PTYTextView.m,v retrieving revision 1.320 diff -u -r1.320 PTYTextView.m --- PTYTextView.m 23 Sep 2008 23:26:36 -0000 1.320 +++ PTYTextView.m 25 Sep 2008 18:21:07 -0000 @@ -44,6 +44,8 @@ #import "ITConfigPanelController.h" #import <iTerm/Tree.h> +#import <Foundation/NSException.h> + #include <sys/time.h> #include <math.h> @@ -2601,6 +2672,7 @@ BOOL renderBold; BOOL tigerOrLater = (NSAppKitVersionNumber > NSAppKitVersionNumber10_3); NSFontManager *fontManager = [NSFontManager sharedFontManager]; + int retryAttempts = 5; //NSLog(@"%s: drawing char %c", __PRETTY_FUNCTION__, carac); //NSLog(@"%@",NSStrokeWidthAttributeName); @@ -2646,9 +2718,47 @@ nil]; } + + crap = [NSString stringWithCharacters:&carac length:1]; + +retry: + @try + { + [image lockFocus]; + } + @catch (NSException *e) + { + /* Work around a bug in Leopard. Sometimes the call to + * lockFocus fails with the following error messages: + * iTerm[13285] <Warning>: CGSResolveShmemReference : reference offset (65296) exceeds bounds (32768) on shmem obj 0x2f69 + * Error (1000) creating CGSWindow + * + * The net result is that iTerm locks up (deadlock in NSLock + * because due to code flow caused by the uncaught exception + * VT100Screen is locked twice by the same thread). + * Just retry locking, up to five times. If it still doesn't + * work log and rethrow. + */ + if ([e name] == NSInternalInconsistencyException) + { + if (--retryAttempts == 0) + { + NSLog(@"%s: Error while lock focus on image !"); + @throw; + } + else + { + // Unfortunately there's no @retry... + goto retry; + } + } + else + { + // Not the exception we were expecting. + @throw; + } + } - crap = [NSString stringWithCharacters:&carac length:1]; - [image lockFocus]; [[NSGraphicsContext currentContext] setShouldAntialias: antiAlias]; if (bgColor) { bgColor = [bgColor colorWithAlphaComponent: useTransparency ? 1.0 - transparency : 1.0]; -- Marc Haisenko ma...@da... |