[0.12.7] CTD with a mod UI

This subforum contains all the issues which we already resolved.
Post Reply
cpw
Long Handed Inserter
Long Handed Inserter
Posts: 59
Joined: Tue Aug 12, 2014 3:47 pm
Contact:

[0.12.7] CTD with a mod UI

Post by cpw »

Pretty sure a mod UI isn't supposed to cause a CTD. Not sure how I triggered it exactly, smart trains mod wasn't closed properly perhaps when exiting the train GUI? The error seems to have come from the destructor of a GUI element, perhaps it's a race condition?

Log file attached, it appears to have a pretty complete symbol dump..
Attachments
factorio-current.log
(9.59 KiB) Downloaded 165 times

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.12.7] CTD with a mod UI

Post by Rseding91 »

Do you have the save and mods? Also a best-guess as to how you caused it would help.
If you want to get ahold of me I'm almost always on Discord.

cpw
Long Handed Inserter
Long Handed Inserter
Posts: 59
Joined: Tue Aug 12, 2014 3:47 pm
Contact:

Re: [0.12.7] CTD with a mod UI

Post by cpw »

It wasn't repeatable, so far. The mod was most likely the "Smart Trains" mod - I noticed that the UI elements it spawned somehow lingered after closing the main train window. The way the error occured seems to be related to interacting with the smart trains GUI. No doubt there's a bug in smart trains, but I would anticipate the sandbox should try and prevent a mod from causing a CTD.

SmartTrains: https://forums.factorio.com/forum/vie ... 97&t=14432 (I have 0.3.66 installed locally at present).
You can see the complete mod list in the log file, but the activity was around configuring a train line in SmartTrains, and then trying to exit the train GUI.

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [0.12.7] CTD with a mod UI

Post by Choumiko »

cpw wrote:The mod was most likely the "Smart Trains" mod - I noticed that the UI elements it spawned somehow lingered after closing the main train window. The way the error occured seems to be related to interacting with the smart trains GUI. No doubt there's a bug in smart trains, but I would anticipate the sandbox should try and prevent a mod from causing a CTD.
In case it helps, some probably relevant parts of the code: (starts at ~ line 672 in control.lua )

Code: Select all

function ontick(event)
--snip
if event.tick%10==9  then
    local status,err = pcall(
      function()
        for pi, player in pairs(game.players) do
          if player.opened ~= nil and not global.player_opened[player.name] then
            game.raise_event(events["on_player_opened"], {entity=player.opened, player_index=pi})
            global.player_opened[player.name] = player.opened
          end
          if global.player_opened[player.name] and player.opened == nil then
            game.raise_event(events["on_player_closed"], {entity=global.player_opened[player.name], player_index=pi})
            global.player_opened[player.name] = nil
          end
        end
      end
    )
    if not status then
      pauseError(err, "on_tick_players")
    end
  end
end

function on_player_opened(event)
  if event.entity.valid and game.players[event.player_index].valid then
    if event.entity.type == "locomotive" and event.entity.train then
      global.playerPage[event.player_index] = {schedule=1,lines=1}
      local name = event.entity.backer_name or event.entity.name
      local trainInfo = getTrainFromEntity(event.entity)
      removeInvalidTrains(true)
      GUI.create_or_update(trainInfo, event.player_index)
      global.guiData[event.player_index] = {rules={}}
      global.openedTrain[event.player_index] = event.entity.train
    elseif event.entity.type == "train-stop" then
      global.playerPage[event.player_index] = {schedule=1,lines=1}
      GUI.create_or_update(false, event.player_index)
      global.guiData[event.player_index] = {rules={}}
      global.openedName[event.player_index] = event.entity.backer_name
    end
  end
end

function on_player_closed(event)
  if event.entity.valid and game.players[event.player_index].valid then
    if event.entity.type == "locomotive" and event.entity.train then
      local name = event.entity.backer_name or event.entity.name
      GUI.destroy(event.player_index)
      global.guiData[event.player_index] = nil
      global.openedTrain[event.player_index] = nil
      --set line version to -1, so it gets updated at the next station
      local train = getTrainFromEntity(event.entity)
      if train.line and train.lineVersion ~= 0 then
        train.lineVersion = -1
      end
    elseif event.entity.type == "train-stop" then
      GUI.destroy(event.player_index)
      global.guiData[event.player_index] = nil
      if event.entity.backer_name ~= global.openedName[event.player_index] then
        on_station_rename(event.entity, global.openedName[event.player_index])
      end
    end
  end
end
The lingering comes from only checking if an inventory was opened/closed every 10 ticks.
GUI.destroy looks like (GUI.lua, ~ line 50)

Code: Select all

  destroyGui = function (guiA)
    if guiA ~= nil and guiA.valid then
      guiA.destroy()
    end
  end,

  destroy = function(player_index)
    local player = false
    if type(player_index) == "number" then
      player = game.players[player_index]
    else
      player = player_index
    end
    if player.valid then
      GUI.destroyGui(player.gui[GUI.position][GUI.windows.root])
    end
  end,
One thing i notice is i don't check whether player.gui[GUI.position] is nil, but that should error before trying to destroy?
I probably should/could pcall on_player_closed/opened

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [0.12.7] CTD with a mod UI

Post by kovarex »

Yes, nil checks when destroying gui elements are on place. This particular error looks like some other problem, I will try to investigate.

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [0.12.7] CTD with a mod UI

Post by kovarex »

And yes, it was internal agui issue that is now fixed for 0.12.8

Post Reply

Return to “Resolved Problems and Bugs”