[0.16.7] pcall crash - Entity is not programmable-speaker
Posted: Mon Dec 25, 2017 11:47 pm
I was using console to export properties of `game.player` to a JSON file (for debugging a future mod) and found a problem that some properties are not safe to read, e.g.:
When I tried to work around that error, I managed to reliably crash the game (on Mac, no mods, fresh game, log attached). To reproduce, open console (`) and execute following command:
If it helps, following version works, where I didn't combine `pcall` with the `node.help()` ¯\_(ツ)_/¯:
I suspect this might be low priority => can I ask for some advice how to detect (skip) unsafe lua table indexes without crashing please?
Code: Select all
/c game.player.print(type(game.player.character.alert_parameters))
Cannot execute command. Error: Entity is not programmable-speaker.
Code: Select all
/c
function crash(node)
local help = node.help()
help = help:gsub('.*Values:', '')
for k in help:gmatch('%s*([^[]+) %[R[^[]*]') do
local success, result = pcall(function() return node[k] end)
end
end
crash(game.player.character)
Code: Select all
/c
function works(node)
local help = 'active [R] alert_parameters [R] speed [R]'
help = help:gsub('.*Values:', '')
for k in help:gmatch('%s*([^[]+) %[R[^[]*]') do
local success, result = pcall(function() return node[k] end)
game.player.print(k .. ': ' .. tostring(result))
end
end
works(game.player.character)