From 7f7914ef97afe8fc0c16340d596a83a62ce158e4 Mon Sep 17 00:00:00 2001 From: fredkiefer Date: Wed, 25 Mar 2009 08:40:38 +0000 Subject: [PATCH] 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 --- ChangeLog | 6 ++++++ Source/NSGraphicsContext.m | 19 ++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2ffb7a869..d108b1de8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-03-25 Fred Kiefer + + * 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 * Source/NSTextView.m (-initWithFrame:textContainer:, diff --git a/Source/NSGraphicsContext.m b/Source/NSGraphicsContext.m index b9ee2142f..2badffae3 100644 --- a/Source/NSGraphicsContext.m +++ b/Source/NSGraphicsContext.m @@ -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