Jump to content

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.



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.)

Link to comment
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. 

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html


Link to comment
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...