Persistent data is completely lost if game closed too fast!

In this forum we discuss the future of Ren'Py, both bug fixes and longer-term development. Pre-releases are announced and discussed here.
Post Reply
Message
Author
iichan_lolbot
Veteran
Posts: 206
Joined: Tue Dec 30, 2008 9:18 am
Projects: iichan erogame
Contact:

Persistent data is completely lost if game closed too fast!

#1 Post 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

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

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

#2 Post 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.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

iichan_lolbot
Veteran
Posts: 206
Joined: Tue Dec 30, 2008 9:18 am
Projects: iichan erogame
Contact:

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

#3 Post 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.
Attachments
persistent.zip
(26.14 KiB) Downloaded 26 times

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

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

#4 Post 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.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

iichan_lolbot
Veteran
Posts: 206
Joined: Tue Dec 30, 2008 9:18 am
Projects: iichan erogame
Contact:

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

#5 Post 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?

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

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

#6 Post 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.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

iichan_lolbot
Veteran
Posts: 206
Joined: Tue Dec 30, 2008 9:18 am
Projects: iichan erogame
Contact:

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

#7 Post 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?

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

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

#8 Post 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.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: No registered users