Page 1 of 1

[0.18.3] Replay desync after a few minutes.

Posted: Tue Feb 04, 2020 10:31 pm
by nepp95
Hello,

I am trying to create a timelapse from replay. For this I have edited the control.lua, so there we go already :roll:
I don't know if this is considered a bug (or just me being stupid.) but I thought I'd report it anyway, and let you be the judge of that.

The only change I made is adding below code to the control.lua.
Load replay. Put in on, say, 4x speed. Wait a few seconds. Error. (I say minutes in the title because it is fast forwarded ;) )

Added to control.lua:

Code: Select all

script.on_event(defines.events.on_tick, function(event)
   if event.tick % 3600 == 0 then --every 60 seconds
	
	local counter = event.tick / 3600
        local x_size = 1024
        local y_size = 1024
        local x_center = 0
        local y_center = 0
        local x_radius = 4
        local y_radius = 4
        local zoom = 0.5
        local anti_alias = false
        local ent_info = true

        game.surfaces[1].daytime = 0

        for j=-y_radius,y_radius do
            for i=-x_radius,x_radius do
                game.take_screenshot{resolution = {x = x_size, y = y_size},
                    zoom = zoom,
                    surface = game.surfaces[1],
                    allow_in_replay = true,
                    position = {i*x_size/32/zoom + x_center, j*y_size/32/zoom + y_center},
                    show_entity_info = ent_info,
                    anti_alias = anti_alias,
                    path = counter.."_image_"..j+y_radius.."_"..i+x_radius..".png"}
            end
        end
   end
end)
Attached save, log and error screenshot.

Kind regards,
Niels

Re: [0.18.3] Replay desync after a few minutes.

Posted: Tue Feb 04, 2020 10:37 pm
by boskid

Code: Select all

game.surfaces[1].daytime = 0
This changes game state so during replay, it is no longer same as it was when creating and so crc is different. Not a bug.

Re: [0.18.3] Replay desync after a few minutes.

Posted: Thu Feb 06, 2020 10:27 pm
by nepp95
boskid wrote: Tue Feb 04, 2020 10:37 pm

Code: Select all

game.surfaces[1].daytime = 0
This changes game state so during replay, it is no longer same as it was when creating and so crc is different. Not a bug.
Aha.. So this only works when actually playing, and not in replay?

Re: [0.18.3] Replay desync after a few minutes.

Posted: Fri Feb 07, 2020 11:36 am
by boskid
nepp95 wrote: Thu Feb 06, 2020 10:27 pm Aha.. So this only works when actually playing, and not in replay?
Changing control.lua of a save file with replay and then doing replay is undefined behavior, but we silently accept that as long as changes do not produce difference in game state. Your changes in control.lua introduced difference in game state and this is why there is desync. Playing game any further would be pointless since your inputs would no longer align with state of game. Taking screenshot does not change game state. Changing daytime changes game state.

Simple case how changing daytime could desync: lamps could consume less energy, so some assemblers could produce item early (for example ammo) making it in time to turret and biters could be defeated, and differences would cascade everywhere.

Re: [0.18.3] Replay desync after a few minutes.

Posted: Fri Feb 07, 2020 1:12 pm
by Klonan
Maybe you can change the day time, take the screenshot, and then set it back to what it was

Re: [0.18.3] Replay desync after a few minutes.

Posted: Fri Feb 07, 2020 1:13 pm
by posila
Klonan wrote: Fri Feb 07, 2020 1:12 pm Maybe you can change the day time, take the screenshot, and then set it back to what it was
You can't (or you can, but it won't work) ... screenshots are processed after update finishes, before rendering.

Re: [0.18.3] Replay desync after a few minutes.

Posted: Fri Feb 07, 2020 1:41 pm
by Klonan
posila wrote: Fri Feb 07, 2020 1:13 pm
Klonan wrote: Fri Feb 07, 2020 1:12 pm Maybe you can change the day time, take the screenshot, and then set it back to what it was
You can't (or you can, but it won't work) ... screenshots are processed after update finishes, before rendering.
Hmm, maybe settings surface.min_darkness will work, if its not in the CRC

Or making a script render light over the whole factory

Re: [0.18.3] Replay desync after a few minutes.

Posted: Fri Feb 07, 2020 1:51 pm
by darkfrei
:idea: Here must be something like player.replay_min_darkness to change the min darkness for player view, but not surface.

Re: [0.18.3] Replay desync after a few minutes.

Posted: Sat Feb 08, 2020 10:15 pm
by nepp95
Maybe an option in replay to have a certain lightness (or disable darkness entirely.) But only have this change in the render, not in the update, so everything still does what it needs to do (lights, solar panels etc). Will look weird of course to have lights on while it isn't dark at all, but for people needing this option, I don't think that will be a problem. And even that could be cut out of the render.

Just thinking here. Don't know how you've got the update/render loops built.