So time to time we have people reporting corrupted project files due to unknown error and the problem is that often even the autosave also get corrupted somehow.
It is just happened to me, GDevelop was crash when I pressed preview and File size = 0 KB. The entire project is gone. Fortunately, I did pickup the habit of making multiple backups often so in my case no harm was done. But I can imagine when someone working hours on a project without making backups and suddenly everything is gone not to mentions when beginners working days and weeks and months without making a backup.
So, I think in my case what happened was, as I did edit the project, add/remove object, events and saved, something did go wrong and the project file got corrupted and when I pressed preview, GDevelop made a copy of the corrupted project file and then crashed because the project file was invalid and was not able to compile and launch the preview.
So to prevent this from happening, how about if GDevelop would do the following when we press preview:
An empty project file size is 4KB containing only the base JSON data with no scenes, no objects, no events, nothing but the base structure.
- before launch preview check if the project file >= 4KB
- if the project file is < 4KB, abort preview and notify us, something went wrong, attempt to save the project again and then run preview or load the autosave
- copy the project file and create an autosave only if the file size is >= 4KB and the preview did run successfully meaning the project file is valid.
Ok, so I have noticed while I was trying to reproduce the error by editing the project file while GDevelop was running and make it corrupted intentionally, the autosave is not a copy of the project file but a new save based entirely on the editor data.
So then it means, something did go wrong in the editor as I was editing staff, it did not appear visually, did not crash the editor but it is caused the save to fail in both cases when I saved manually and when GDevelop made the autosave when we run preview and maybe this is why it is crashed.
So then, maybe the solution is that to verify the JSON data is valid before save to file, not only if it is a valid JSON but also if the data is actually a valid GDevelop project.
In case it is difficult to verify the project is valid, not corrupted, then maybe the solution is what I believed how it works. Instead of making the autosave an independent save, make it a copy of the project file and before copy the project, check if the size of the project file is >= 4 KB and maybe also if it is valid JSON and then copy.
That’s… weird. We had problems with that in the past and already included multiple verifications and failsafes (including verifying that the project is valid JSON).
Well, it is a valid empty JSON object
So, if you also verify it is a valid GDevelop project including all the base project props then maybe something else did interfere. Basically what I always do is save manually and then run preview with only few seconds difference, so let say if my AV was thinking too long if allow GD to edit the file, or there was a hardware issue that could be a problem if GDevelop does not verify if opening the file for writing was successful or if it was successful but then my AV blocked GD for some reason or was an error and was not able to write the file after all. Can’t see it in the logs though.
if GDevelop does not verify it the JSON is a valid project containing all the project properties then it can still be an error with the IDE.
In the past sometimes if I did copy a lot of events, rename objects things did screw up so the project was not able to load enymore but I was able to edit the JSON and fix. It was impossible to reproduce so never bothered to report it.
In case it is verify everything then, yeah…weird.