Page 1 of 1

Persistent data is completely lost if game closed too fast!

Posted: Thu Nov 03, 2016 8:51 pm
by iichan_lolbot
Hi,

Scenario:
0. Prepare Windows PC with lots of stuff running and AVIRA antivirus enabled
1. Start RenPy game that do some work with persistent data and call renpy.save_persistent() inside some label
2. Play this game for a while, then press "X" button on right-top corner to close the window
3. Select "Yes" in RenPy's exit layout to exit the game
4. Check /saves/ folder
5. Start the game. Check achievements / gallery / whatever persistent data.

Expected result:
4. There is a file named "persistent" with persistent data of the game.
5. Persistent data is not lost.

Actual result:
4. There is a file named "persistent.new" with persistent data of the game.
5. Persistent data is lost, new "persistent" file is created, with smaller size.

Workaround:
Run game with bat-script that renames "persistent.new" to "persistent"

Real-life cases:
A. Our player informed us about disappearing persistent data from Travnica Closed Beta Test.
B. http://steamcommunity.com/app/383460/di ... 074720192/
C. Simple script that we used to reproduce the bug:

Code: Select all

init python:
    theme.roundrect()

label start:
    python:
        for i in range(100):
            val = "x"+`renpy.random.random()`
            persistent.__setattr__(val,1)
        renpy.save_persistent()
    "%(val)s"
    jump start

Re: Persistent data is completely lost if game closed too fa

Posted: Sat Nov 05, 2016 2:52 pm
by PyTom
I landed what I think is a fix for this, where we rename the persistent file twice, so it's always in existence with a valid name. I'm not able to test it, since I'm not about to damage my computer by installing Avira on it. In general, I just have to make a guess about what will work with Windows filesystem semantics, and go from there - and if Avira changes those semantics too badly, then that's a big in that program.

Re: Persistent data is completely lost if game closed too fa

Posted: Sun Nov 06, 2016 5:45 pm
by iichan_lolbot
Thanks, we have tested changes from recent https://raw.githubusercontent.com/renpy ... ocation.py with a PC already severely damaged by this Avira thing, and this is what we have:

I. There is a misprint in your code.

Code: Select all

for pfn in [ self.persistent + ".new", self.persistent ]:
    ...
            data = renpy.persistent.load(self.persistent)
should be

Code: Select all

for pfn in [ self.persistent + ".new", self.persistent ]:
    ...
            data = renpy.persistent.load(pfn)
II. With fix above everything works ALMOST fine, except for one minor bug left:
0. Remove persistent save data.
1. Start the game and notice game window size.
2. Play a game that writes some persistents.
3. Change game window size to something non-default.
4. Close the game.
5. Rename /saves/persistent to /saves/persistent.new manually
6. Start the game.
7. Check persistent game data
8. Check game window size

Expected result:
7. Game data is not lost
8. Game window size is what we set at step 3.

Actual result:
7. Game data is not lost, everything is fine if you do "renpy.persistent.load(pfn)" fix
8. Game window size is reseted to default, as it was at step 1.

We have no idea how is it possible, but all the persistent data is loaded correctly, but the window size is lost.

In attachment - persistent data after step 4 and after step 8 (with some additional playing, unfortunately, but changes in persistent._preferences are seen).
Plus human-readable version of those persistents that I have tred to autoconvert to.

Re: Persistent data is completely lost if game closed too fa

Posted: Sun Nov 06, 2016 9:02 pm
by PyTom
Okay, I've gone ahead and fixed these problems in https://github.com/renpy/renpy/commit/b ... 3e617b67cf .

The window will revert back it its default size if the persistent file in the system specific (ie. ~/.renpy, %APPDATA\RenPy, or ~/Library/RenPy) save directory is removed. I'm fine with this, I think - it makes sense to reset the window size if the game switches computers.

Re: Persistent data is completely lost if game closed too fa

Posted: Mon Nov 07, 2016 7:33 pm
by iichan_lolbot
Thanks! It works fine!

Btw, we are planning a Steam release in a week or two.
Do you think we should wait for RenPy 6.99.12 or we can just backbort those fixes to 6.99.11 and use patched version?

Re: Persistent data is completely lost if game closed too fa

Posted: Tue Nov 08, 2016 7:08 pm
by PyTom
I'd really consider using the nightly. I'm going for a prerelease in the next few days - so it should be pretty stable now.

Re: Persistent data is completely lost if game closed too fa

Posted: Fri Nov 11, 2016 6:55 pm
by iichan_lolbot
PyTom wrote:I'd really consider using the nightly.

You mean https://www.renpy.org/dl/6.99.12/ ? It's 07-Oct-2016, is this OK?
PyTom wrote:I'm going for a prerelease in the next few days - so it should be pretty stable now.
We are planning Steam release on 15th of November. Would there be a prerelease before that date?

Re: Persistent data is completely lost if game closed too fa

Posted: Fri Nov 11, 2016 11:57 pm
by PyTom
No, the nightlies are from http://nightly.renpy.org.

I'm hoping for a prerelease soon - but I can't make any guarantees, since I'm not done with testing yet.