Try to deal with the case when there is no current context.

May happen in secondard threads. Fixes #25943.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@28133 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2009-03-25 08:40:38 +00:00
parent 48f6a535ad
commit b9b3df0631
2 changed files with 20 additions and 5 deletions

View file

@ -1,3 +1,9 @@
2009-03-25 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSGraphicsContext.m (-restoreGraphicsState,
-saveGraphicsState:) Try to deal with the case when there is no
current context. May happen in secondard threads. Fixes #25943.
2009-03-25 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSTextView.m (-initWithFrame:textContainer:,

View file

@ -236,15 +236,20 @@ NSGraphicsContext *GSCurrentContext(void)
NSGraphicsContext *ctxt;
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
NSMutableArray *stack = [dict objectForKey: NSGraphicsContextStackKey];
if (stack == nil || [stack count] == 0)
if (stack == nil)
{
[NSException raise: NSGenericException
format: @"restoreGraphicsState without previous save"];
}
// might be nil, i.e. no current context
ctxt = [stack lastObject];
[NSGraphicsContext setCurrentContext: ctxt];
[stack removeLastObject];
[ctxt restoreGraphicsState];
if (ctxt)
{
[stack removeLastObject];
[ctxt restoreGraphicsState];
}
}
+ (void) saveGraphicsState
@ -257,9 +262,13 @@ NSGraphicsContext *GSCurrentContext(void)
stack = [[NSMutableArray allocWithZone: _globalGSZone] init];
[dict setObject: stack forKey: NSGraphicsContextStackKey];
}
// might be nil, i.e. no current context
ctxt = GSCurrentContext();
[ctxt saveGraphicsState];
[stack addObject: ctxt];
if (ctxt)
{
[ctxt saveGraphicsState];
[stack addObject: ctxt];
}
}
+ (void) setGraphicsState: (int)graphicsState