Generated images not saved when exiting blender
Open, NormalPublic

Description

There has been an old issue with the image creation workflow in blender, made more apparent now that texture tools are getting more attention. The problem is that generated images can easily get lost on various occasions.

  • User exits blender without saving them
  • Trying to save all dirty images will skip generated images
  • Changing the generated image type to float or the color management (CM) space will delete all contents of the image.
  • Undoing after baking

There are various ways to deal with those issues:

  • Have a preference for autosaving dirty images when closing blender. Alternative of having a pop-up prompt makes the exit popup complicated and only supported on Windows/Mac.
  • Saving dirty images operator creates an image file for all generated images.
  • Saving can be done immediately on generation so reloading the file on CM change will reload the file correctly. We are forfeiting format change (float/byte) at a later time this way but I feel this is not such a big deal, this choice should usually be done early on. It might make sense to only treat blank type generated images this way.
  • Pack images immediately on generation. This will only work with byte images, since only those allow packing as pngs. We might allow packing in memory in exr format too by using a temporary exr file to save to before packing (unpacking will be problematic later though).

All those require having a default place to store generated images in.

  • Have a preference for a directory that handles generated texture storage (this could be the Textures directory, but it's possible that there will be too many name collisions and file pollution)
  • Texture directory can always resides in a directory beside the project file. This will of course require the user to save the file first. If file is not saved, file storage can be done on tmp. Downside is that if user saves blend file after images have been saved, the tmp files could get wiped out. Alternatively, file storage could be done on Textures directory (with name collision issue/file pollution, mentioned above)

I've been bit by this a couple times recently. Nice to see you're tackling this issue.

My 2¢:

Dirty images should be saved when saving the blend file. There could be a toggle in File > External Data, like the one for auto-packing. The autosaving could be based on an op, that way it's available for scripting too.

The problem with saving/packing on generation is that it would fill the folders/blend with unused or throw-away images.

I agree with keeping them in the textures directory. Maybe add a suffix like "_001" to filenames if there's already a file with that name (in the first autosave).

I've also fallen victim to this a couple times, and I've seen more than one question on blender.stackexchange where the user assumed saving the .blend would save the images too.

I pretty much agree with januz, but what about the undo issue? How can that be solved?
If you paint/bake/modify an image and then undo in object mode, those changes are lost, immediately and forever. As far as I can tell, none of the proposed solutions really prevent this from happening.

Maybe an option to auto-save on image modification, so changes are always saved?

I think the undo issue is related to saving/not saving, as blender undo / redo is basically a file save/ file load to memory (with diffing, and since blender save/load is basically a memory dump, this is fast enough)

So if blender is saving incremental versions, this would somewhat mitigate the undo issue as well, as blender could also do a save/load then...

Auto saving on every modification might be super slow?

Another thought: similar to text buffers, could a modified image be treated like a packed version of the image that is out-of-sync with the image on disk (until saved or reloaded) ? Obviously this would make the size of the file grow (similar to packing) so it might not always be practical.