I have some rendering code, which relies on DrawingContext.PushClip
and the corresponding Pop
method.
protected override void OnRender(DrawingContext drawingContext)
{
drawingContext.PushClip(whatever);
OnRenderInternal(...);
drawingContext.Pop();
}
Now, let's assume that something really bad happens in the
OnRenderInternal
method and it throws an exception (in this casePop
will never get called). Would this break the entire rendering process or the drawing context will revert itself to some "safe" state before performing other operations (and no clipping will occure for other renderable items)?Basically, should I always care about reverting the drawing context to its initial state when performing rendering operations?
I realize that in this simple case I can avoid troubles by using a
try-finally
statement, but what would happen if I forget to preserve the correctPush / Pop
stack?