On Mon, Jan 19, 2009 at 6:07 AM, Graham Cox <graham....@bigpond.com> 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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to