Page MenuHome

UI: Sanitize threaded preview creation with undo
ClosedPublic

Authored by Julian Eisel (Severin) on Jan 2 2021, 8:00 PM.

Details

Summary

With undo/redo after creating assets, previews of the "Current File"
asset library would often go missing, e.g. see T83884.
What I thought was just a simple error with flags, turned out to be a
bigger problem:
The preview generation in a background job will eventually modify ID
data, but the undo push was done prior to that. So obviously, an undo
then would mean the preview is lost.

This patch makes it so undo/redo will regenerate the preview, if the preview
rendering was invoked but not finished in the undone/redone state.

The preview flag PRV_UNFINISHED wasn't entirely what we needed. So I had to
change it to a slightly different flag.

Diff Detail

Repository
rB Blender
Branch
temp-preview-undo-sanitize (branched from master)
Build Status
Buildable 12057
Build 12057: arc lint + arc unit

Event Timeline

Julian Eisel (Severin) requested review of this revision.Jan 2 2021, 8:00 PM
  • Avoid need for versioning, reuse old flag bit
Bastien Montagne (mont29) requested changes to this revision.Jan 8 2021, 12:35 PM

Generally looks good, besides picky notes below.

My main issue with this patch is that it will restart ID previews job on each memfile undo step... Not sure if there would be a way to deffer that to after all undo/redo steps needed have been performed?

source/blender/editors/undo/memfile_undo.c
156

We try to put action (verb) at the end of function names usually: memfile_undosys_unfinished_id_previews_restart ?

294–298

Needs some comment similar to above I think?

This revision now requires changes to proceed.Jan 8 2021, 12:35 PM
Julian Eisel (Severin) marked an inline comment as done.
  • Address review requests

My main issue with this patch is that it will restart ID previews job on each memfile undo step... Not sure if there would be a way to deffer that to after all undo/redo steps needed have been performed?

It could be done in ed_undo_step_impl() I guess, but that may either mean iterating over all IDs to check if their job needs to be restarted, or passing some info from the undo decoding to it, e.g. which data-blocks were modified.
That's not really great either.
Not sure if it's worth it, it's not like the job stuff is very expensive and it only happens in few cases (undoing after a preview was created).

  • Update to latest master
Bastien Montagne (mont29) requested changes to this revision.Sep 29 2021, 4:37 PM
Bastien Montagne (mont29) added inline comments.
source/blender/editors/undo/memfile_undo.c
171

Am not particularly happy that this gets called here.

Clearing/tagging preview to be updated in undo code is fine. But think the actual call for update should happen from UI user (in that case, the asset browser/file browser draw code)?

This revision now requires changes to proceed.Sep 29 2021, 4:37 PM
  • Merge branch 'master' into arcpatch-D9974
Julian Eisel (Severin) planned changes to this revision.Nov 1 2021, 2:38 PM
source/blender/editors/undo/memfile_undo.c
171

Since the preview is ID data not UI data, that wouldn't work. You wouldn't want your asset previews to be lost just because you didn't happen to display that particular asset in the Asset Browser after an undo.
But what we could do instead is somehow schedule an update, that is then performed immediately after the undo.

So for example, in wm_event_do_notifiers(), we could listen to NC_WM | ND_UNDO and call some ED_preview_restart_render_pending() there. We'd have to do a FOREACH_MAIN_ID_BEGIN() iteration there which isn't nice. We could avoid it with some global flag set here in the undo system, indicating that some preview needs to be restarted. Is that worth it?

  • Only schedule preview regeneration on undo/redo, don't execute it
Bastien Montagne (mont29) requested changes to this revision.Nov 23 2021, 4:33 PM
Bastien Montagne (mont29) added inline comments.
source/blender/editors/undo/memfile_undo.c
259–262

Since you kill the preview job, you have no guarantee that existing (re-used) IDs already have a valid preview. So this code should be executed over the whole bmain, unconditionally.

This revision now requires changes to proceed.Nov 23 2021, 4:33 PM
Julian Eisel (Severin) marked an inline comment as done.
  • Address error found in review
  • Remove byte order mark changes done by IDE
This revision is now accepted and ready to land.Nov 24 2021, 8:56 AM

Thanks! Committed now.