From 21b0b24b1414905b5075c39e8650af07acbef62a Mon Sep 17 00:00:00 2001 From: chrox Date: Mon, 10 Mar 2014 17:29:11 +0800 Subject: [PATCH] fix input timer queue if new timer has a timeout later than a timer in queue, the new timer will be discarded and never be pushed into timer queue. This is fixed by pushing new timer without timeout checking and then sorting the queue according to timer timeouts. This should fix #520 and #495. --- frontend/ui/input.lua | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/frontend/ui/input.lua b/frontend/ui/input.lua index d3f32e8c8..ba229bf07 100644 --- a/frontend/ui/input.lua +++ b/frontend/ui/input.lua @@ -433,15 +433,10 @@ function Input:setTimeout(cb, tv_out) callback = cb, deadline = tv_out, } - for k,v in ipairs(self.timer_callbacks) do - if v.deadline > tv_out then - table.insert(self.timer_callbacks, k, item) - break - end - end - if #self.timer_callbacks <= 0 then - self.timer_callbacks[1] = item - end + table.insert(self.timer_callbacks, item) + table.sort(self.timer_callbacks, function(v1,v2) + return v1.deadline < v2.deadline + end) end function Input:handleKeyBoardEv(ev)