• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Dealing with exceptions in a drawing stack
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Dealing with exceptions in a drawing stack (From: Graham Cox <email@hidden>)
 >Re: Dealing with exceptions in a drawing stack (From: "Kyle Sluder" <email@hidden>)
 >Re: Dealing with exceptions in a drawing stack (From: Graham Cox <email@hidden>)
 >Re: Dealing with exceptions in a drawing stack (From: email@hidden)
 >Re: Dealing with exceptions in a drawing stack (From: Graham Cox <email@hidden>)
 >Re: Dealing with exceptions in a drawing stack (From: Kyle Sluder <email@hidden>)
 >Re: Dealing with exceptions in a drawing stack (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Memory allocation issues with NSObject and NSString
  • Next by Date: Re: Dealing with exceptions in a drawing stack
  • Previous by thread: Re: Dealing with exceptions in a drawing stack
  • Next by thread: Re: Dealing with exceptions in a drawing stack
  • Index(es):
    • Date
    • Thread