Sign in to follow this  
MJW

Is IsCancelRequested set during OnSetRenderInfo?

Recommended Posts

In cases where the entire image has to be processed as a whole, it's often necessary to do a lot of processing in OnSetRenderInfo (or at least I don't know any other way). If a control changes while OnSetRenderInfo is active, is IsCancelRequested set so the processing can be aborted, or does that only happen after OnRender is called?

 

My question is related to a comment by Rick Brewster, which says.

 

Quote

The way it works is,

1. Your Effect is instantiated (your constructor is called)

2. The user configures stuff (your CreateEffectConfigDialog() is called, or IndirectUI just does it for you)

3. OnSetRenderInfo() is called with the new token.

4. OnRender() is called many times, once for each section of the region of interest. These calls are made in parallel on multiple threads.

5. If the user changes the configuration (the token), then IsCancelRequested is set to true and Paint.NET waits for any pending OnRender() calls to finish. Go back to step 3. (IsCancelRequested is also reset to false)

If you want you can do all your rendering in OnSetRenderInfo() and then OnRender() would be implemented to do nothing. It doesn't provide a great user experience though.

 

I wasn't sure if that implied that IsCancelRequested was only set during OnRender.

 

EDIT: Actually, I can think of some possible alternatives, such as setting a FirstTime flag in OnSetRenderInfo which is used in OnRender to initiate the entire-image processing.

 

EDIT 2: I believe the answer to my question is Yes. I added a delay loop in OnSetRenderInfo which tested for IsCancelRequested and brought up a MessageBox if it was set. The MessageBox came up regularly when I changed the controls. So unless I made a mistake, or misunderstand something, IsCancelRequested is set in OnSetRenderInfo. (I certainly hope that's true.)

Share this post


Link to post
Share on other sites

If it's set, then it's set :)

 

I don't think many plugins check this flag during OnSetRenderInfo. The flag gets most of its value from being checked internally before dispatching any call to Render, which doesn't require plugins to specifically check it in order to get cancelled. 

Share this post


Link to post
Share on other sites

I hope it will continue to be set in future versions. I've always checked it in OnSetRenderInfo when doing time-consuming operations, though in the back of my mind I've wondered if the tests did any good. I also usually check it per-row in Render, though now that you point out that it's checked internally, maybe that's not really necessary. It's much more necessary for effects that render in OnSetRenderInfo, since they usually render a full frame's worth before returning.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this