pasbi/ommpfritt

Crash during overwrite nukes the existing file

pasbi opened this issue · 0 comments

pasbi commented

Describe the bug
When saving the scene to some existing file (i.e., attempting to overwrite it) and the application crashes during the serialization,
that file will be empty.
That is because a ofstream to that file is opened first (which already erases the content), then the serialization happens into a buffer, then the buffer is written to the ofstream.

To Reproduce
Steps to reproduce the behavior:

  1. Create some scene (from scratch or load it)
  2. File -> Save As -> pick existing file (i.e., attempt to overwrite it) and make sure that omm crashes within the serialization code. (Note: That crash is not part of this bug report. Any crash during serialization will do. If you just want to reproduce: put an abort into the serialization code)
  3. The file is empty now.

Expected behavior
Losing the work we just wanted to save is super annoying already, but losing the work before, too, is even worse.
I would expect that the overwritten file contains either the most recent save, or at least was not touched if something crashes.

Desktop (please complete the following information):
This problem seems to be independent of the system.

Additional context
The bug should be easy to resolve.
The serialization is stored in a buffer already.
Don't open the file (or stream, whatever), until that serialization has finished without errors.
Then put the buffer into that file/stream and close it.