Page MenuHome

Add a callback to `IDTypeInfo` to allow preservation of some data accross memfile undos
ClosedPublic

Authored by Bastien Montagne (mont29) on Oct 16 2020, 5:23 PM.
Tags
None
Tokens
"Love" token, awarded by Thane5."Like" token, awarded by CobraA."Like" token, awarded by erickblender."100" token, awarded by ckohl_art."Like" token, awarded by andruxa696."Like" token, awarded by hitrpr."Love" token, awarded by kioku."Burninate" token, awarded by MetinSeven."Love" token, awarded by gilberto_rodrigues."100" token, awarded by Zino."Love" token, awarded by Alrob."Like" token, awarded by leha."Like" token, awarded by YAFU."Like" token, awarded by lopoIsaac."Like" token, awarded by TheRedWaxPolice.

Details

Summary

This is essentially adding that new callback, and using it only for already existing Scene's 3DCursor.

Note that the place where this is called has been moved again, after all have been lib-linked, such that those callbacks may also work on ID pointers.

Diff Detail

Repository
rB Blender
Branch
T71759 (branched from master)
Build Status
Buildable 10759
Build 10759: arc lint + arc unit

Event Timeline

Bastien Montagne (mont29) requested review of this revision.Oct 16 2020, 5:23 PM
Bastien Montagne (mont29) created this revision.

This will be a big usability improvement. Though I'm not sure this patch is enough to handle all cases:

  • Brushes can point to texture, image and material datablocks. What happens if you undo the creation of such a datablock pointed to by a brush?
  • When undoing and then redoing the creation of the scene, what happens to the brush pointers?

In both cases it's probably reasonable for the pointers to get lost, but we should avoid crashing.

source/blender/blenloader/intern/readfile.c
6679–6681

This comment is a bit unclear. We do support pointers from the scene tool settings to brush datablocks, (and maybe the WM does as well for tools, not sure). But I guess the point is that all those cases are persistent.

For this to work reliably we will need a way to visit and validate pointers from/to brushes on each undo step.

A down side for clearing the pointers is it means undoing (back to the initial state), then redoing can leave you with cleared ID pointers.

source/blender/blenloader/intern/readfile.c
6635

ToolSettings holds references to other ID's

  • objects, via GP_Sculpt_Guide.reference_object & Sculpt.gravity_object, ParticleEditSettings.shape_object for example.
  • palettes via Paint.palette
  • images via ImagePaintSettings...
  • scene via ParticleEditSettings.scene

... probably others.

A down side for clearing the pointers is it means undoing (back to the initial state), then redoing can leave you with cleared ID pointers.

We could undo/redo the datablock pointers, but leave all other fields in brushes and tool settings unchanged? This could be implemented by cleaing invalid datablock pointers automatically, and (manually?) implementing a function to copy over datablock pointers from the undo-restored brush or tool settings where it makes sense.

At least for objects, materials, images, and scenes this is probably good. Palette datablock should be handled like brushes, and not be part of scene data. Textures are the more complicated case, where they can be either scene data or purely brush/UI data, not sure there is a great solution in the current design. Probably you also want to copy them over.

Bastien Montagne (mont29) planned changes to this revision.EditedOct 19 2020, 5:03 PM

In fact, I wonder if it's that important to keep brushes themselves out of undo? Most of the issues users are complaining about are actually related to tool settings, not brushes themselves?

Now that I think about it a bit more, am somewhat wary about removing more ID types from undo process tbh.

So indeed maybe have a util function to only swap (i.e. keep) regular data from old datablocks into new ones accross undo would be a much cleaner and future-proof solution (would even add it as a callback to IDTypeInfo structure itself. That would also make that 'hack' a bit more obvious/easy to find in the code, instead of hiding it in a specific function in readfile.c.

Agree syncing non-pointer data seems a lot safer than bypassing non-screen ID's from undo.

The down-sides with this are it could be a tedious to add the callbacks that sync data, but that's a lot less hassle than properly dealing with brushes/textures/palettes/images being added/removed.

WIP refactor, please ignore for now.

Bastien Montagne (mont29) planned changes to this revision.Oct 20 2020, 6:31 PM

Rebased on current master.

Bastien Montagne (mont29) retitled this revision from Fix T71759: Sculpt/Vertex/Weight Paint Brush Size Gets Undone After Undoing a Stroke. to Add a callback to `IDTypeInfo` to allow preservation of some data accross memfile undos.Oct 22 2020, 1:17 PM
Bastien Montagne (mont29) edited the summary of this revision. (Show Details)

Rebased against current master.

This revision is now accepted and ready to land.Nov 2 2020, 12:48 PM