Re: Dealing with exceptions in a drawing stack
Re: Dealing with exceptions in a drawing stack
- Subject: Re: Dealing with exceptions in a drawing stack
- From: Michael Ash <email@hidden>
- Date: Mon, 19 Jan 2009 11:52:53 -0500
On Mon, Jan 19, 2009 at 6:07 AM, Graham Cox <email@hidden> wrote:
> What does appear to help a lot is saving the current context at the top of
> the drawing stack and putting it back explicitly at the end (as per my
> previously posted code snippet). If the save/restores are balanced,
> effectively this is a no-op, as I'm putting back the same context that I
> saved. If an exception occurred, the save/restores are unbalanced, and this
> code forces it to balance - thus, the NSScrollView is no longer badly
> screwed up and things can progress almost normally.
>
> My question is, is this in any way legal?
>
> In other words, the call stack looks like this:
>
>
> @try
> {
> save graphics state
> save graphics state
> save graphics state
> save graphics state
> // normally draw stuff, but may throw
> an exception
> restore graphics state
> restore graphics state
> restore graphics state
> restore graphics state
> }
> @catch
> {
> // if there was an exception, the context stack is unbalanced - how
> to rebalance it in a legal way before exiting?
> }
How about wrapping save/restore in a macro, and expanding them to use
@try/@finally? For example:
#define SAVE_GSTATE @try { [NSGraphicsContext saveGraphicsState];
#define RESTORE_GSTATE } @finally { [NSGraphicsContext restoreGraphicsState]; }
Then use those everywhere instead of the raw calls.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden