Added error handling in the case of a corrupt replay

This commit is contained in:
Ishaan Bhardwaj 2023-07-16 00:46:45 -04:00
parent 7199aa7ef6
commit c693871621

View File

@ -14,9 +14,13 @@ function ReplaySelectScene:new()
replay_file_list = love.filesystem.getDirectoryItems("replays") replay_file_list = love.filesystem.getDirectoryItems("replays")
for i=1,#replay_file_list do for i=1,#replay_file_list do
local data = love.filesystem.read("replays/"..replay_file_list[i]) local data = love.filesystem.read("replays/"..replay_file_list[i])
local new_replay = binser.deserialize(data)[1] local success, new_replay = pcall(
function() return binser.deserialize(data)[1] end
)
if success then
replays[#replays + 1] = new_replay replays[#replays + 1] = new_replay
end end
end
table.sort(replays, function(a, b) table.sort(replays, function(a, b)
return a["timestamp"] > b["timestamp"] return a["timestamp"] > b["timestamp"]
end) end)