Page 1 of 1
wierd bug with transport lines and game.tick
Posted: Sun Apr 24, 2016 9:42 am
by Simcra
In multiplayer I have a wierd desync issue with one of our mods, I've tried to fix it to no avail and quite frankly have no idea what I'm doing anymore. I have the feeling that it has something to do with the transport belts not performing the same action on all clients at the same time. The desync only occurs when I connect the item elevators back up to the conveyor belt, otherwise no desync occurs. My appologies if I placed this in the wrong forum, I'm new to this.
I need some assistance improving on this code, any help would be appreciated:
Code: Select all
function move_items(function_name)
if game.tick%6==0 then
for key,elevator in pairs(global.item_elevator) do
if not(elevator.input and elevator.output and elevator.input.valid and elevator.output.valid) then
if elevator.input.valid then elevator.input.destroy() end
if elevator.output.valid then elevator.output.destroy() end
global.item_elevator[key]=nil
elseif elevator.input.active or elevator.output.active then
for laneI=1,2 do
lane_input = elevator.input.get_transport_line(laneI)
lane_output = elevator.output.get_transport_line(laneI)
if lane_input.get_item_count() > 0 and lane_output.can_insert_at_back() then
local item_to_move = {name = next(lane_input.get_contents()), count = 1}
lane_input.remove_item(item_to_move)
lane_output.insert_at_back(item_to_move)
end
end
end
end
end
end
Please request any more information if it is necessary.
Re: wierd bug with transport lines and game.tick
Posted: Sun Apr 24, 2016 10:39 am
by Choumiko
Not sure what's causing it
Code: Select all
local item_to_move = {name = next(lane_input.get_contents()), count = 1}
looks strange to me, but that's probably only because i haven't used next() at all.
Often script.on_load can be a cause for desyncs, can you post that function (if you use it)?
Re: wierd bug with transport lines and game.tick
Posted: Sun Apr 24, 2016 11:25 am
by Simcra
Yeah, here's the appropriate onLoad stuff.
Code: Select all
script.on_load(setup)
function setup()
global.onTickFunctions = global.onTickFunctions or {}
global.elevator_association = global.elevator_association or {}
global.item_elevator = global.item_elevator or {}
global.surface_drillers = global.surface_drillers or {}
global.air_vents = global.air_vents or {}
global.underground_players = global.underground_players or {}
global.surface_associations = global.surface_associations or {}
global.Underground_driving_players = global.Underground_driving_players or {}
global.fluids_elevator = global.fluids_elevator or {}
global.waiting_entities = global.waiting_entities or {}
global.time_spent_dict = global.time_spent_dict or {}
global.selection_area_markers_per_player = global.selection_area_markers_per_player or {}
global.marked_for_digging = global.marked_for_digging or {}
global.digging_pending = global.digging_pending or {}
global.digging_in_progress = global.digging_in_progress or {}
global.digging_robots_deployment_centers = global.digging_robots_deployment_centers or {}
-- move to where I create the first entrance ?
global.onTickFunctions["teleportation_check"] = teleportation_check
global.onTickFunctions["move_items"] = move_items
global.onTickFunctions["fluids_elevator_management"] = fluids_elevator_management -- needed to reset the method and prevent the crash
--global.onTickFunctions["debug"] = debug
end
script.on_event(defines.events.on_tick,
function(event)
for name,fun in pairs(global.onTickFunctions) do
--we pass the name to the function so it can delete itself if it wants to, the function does not remember its own name to prevent closures
if type(fun) == "function" then fun(name) end
if type(fun) == "table" and fun.onTick then fun:onTick(name) end
end
end)
It also desyncs with the previous code for that section, which was
Code: Select all
local item_to_move = {name = "", count = 1}
for name, count in pairs(lane_input.get_contents()) do
item_to_move.name = name
break
end
Re: wierd bug with transport lines and game.tick
Posted: Sun Apr 24, 2016 5:26 pm
by Rseding91
Code: Select all
global.onTickFunctions["teleportation_check"] = teleportation_check
global.onTickFunctions["move_items"] = move_items
global.onTickFunctions["fluids_elevator_management"] = fluids_elevator_management -- needed to reset the method and prevent the crash
Don't store method information in the global table. That's what local tables are for - if you store them in global and then someone connects to the game they're going to change over one player to the next and that will cause a desync.
Re: wierd bug with transport lines and game.tick
Posted: Mon Apr 25, 2016 3:05 am
by Simcra
Here's what I changed, still desyncing.
Code: Select all
function setup()
global.elevator_association = global.elevator_association or {}
global.item_elevator = global.item_elevator or {}
global.surface_drillers = global.surface_drillers or {}
global.air_vents = global.air_vents or {}
global.underground_players = global.underground_players or {}
global.surface_associations = global.surface_associations or {}
global.Underground_driving_players = global.Underground_driving_players or {}
global.fluids_elevator = global.fluids_elevator or {}
global.waiting_entities = global.waiting_entities or {}
global.time_spent_dict = global.time_spent_dict or {}
global.selection_area_markers_per_player = global.selection_area_markers_per_player or {}
global.marked_for_digging = global.marked_for_digging or {}
global.digging_pending = global.digging_pending or {}
global.digging_in_progress = global.digging_in_progress or {}
global.digging_robots_deployment_centers = global.digging_robots_deployment_centers or {}
end
script.on_load(setup)
script.on_event(defines.events.on_tick,
function(event)
if game.tick%60==0 then --every second
end
if game.tick%30==0 then --every 30/60th second
check_waiting_entities(event)
end
if game.tick%20==0 then --every 20/60th second
end
if game.tick%15==0 then --every 15/60th second
digging_planner_check(event)
end
if game.tick%10==0 then --every 10/60th second
teleportation_check(event)
digging_robots_manager(event)
pollution_killing_subsurface(event)
end
if game.tick%6==0 then --every 6/60th second
move_items(event)
fluids_elevator_management(event)
end
if game.tick%5==0 then --every 5/60th second
pollution_moving(event)
end
if game.tick%2==0 then --every 2/60th second
boring(event)
drilling_check(event)
temp_teleportation_check(event)
end
--debug(event)
end)
Is there any way to make global variables which all clients use without causing desync (maybe there's something still broken here)? It seems to just be the item elevators doing it, when we remove the belt attached to them it stops desyncing.
Re: wierd bug with transport lines and game.tick
Posted: Mon Apr 25, 2016 4:56 am
by Rseding91
I'd need to see the full mod to know what you've got wrong that's causing the desync.
Re: wierd bug with transport lines and game.tick
Posted: Mon Apr 25, 2016 5:05 am
by Simcra
EDIT: removed attachment
Re: wierd bug with transport lines and game.tick
Posted: Tue Apr 26, 2016 7:09 am
by Simcra
We tried to reproduce this bug with the standalone multiplayer server from the non-steam version of factorio to no avail, I have yet to test with the headless server but this desync bug is definitely evading me.
Re: wierd bug with transport lines and game.tick
Posted: Tue Apr 26, 2016 7:51 am
by Simcra
Okay I was able to reproduce this desync in both multiplayer through headless server and through nonsteam client (using factorio 0.12.30). Here's what I did:
While using the item elevators -
1. Log all clients into the server
2. Log one client out
3. Log same client back in
4. desync occurs until that client is force closed or item elevators are cleared of all items
Seems to only happen after the client joins the game for a second time since the server was started. I hope this helps.
EDIT:
We just tried to rollback to factorio 0.12.29, turned on cheats and spawned in some stuff to get the map working and so far have not been able to reproduce the desync.
It seems to be related to our map, even after ripping out all other mods desync continues and we have been unable to reproduce desync with a fresh map.
Isolated issue, it is not at all what I thought it was, sorry for wasting your time. Please lock this thread.