So, if I call timer.cancel()
on a non-repeating timer inside its callback, it crashes the engine.
I get this, which makes me think that the timer callback gets unregistered twice in this situation (once by the call to cancel()
and once by the code trying to destroy the timer after its callback got called:
PANIC: unprotected error in call to Lua API (Failed to unregister callback (it was not registered))
I think calling cancel()
in a callback should be a no-op, or return false
meaning the timer is complete.
My code looked something like this:
local go_to_next_slide
function init(self)
self.timer_id = timer.delay(0.5, false, go_to_next_slide)
end
function on_input(self, action_id, action)
if action_id == hash("click") and action.pressed then
go_to_next_slide(self)
end
end
function go_to_next_slide(self)
-- Reset the timer in case go_to_next_slide() is called through user input
timer.cancel(self.timer_id)
-- Do stuff
self.timer_id = timer.delay(5, false, go_to_next_slide)
end
Build time | 2018-06-18T16:06:50.083684 |
Defold channel | editor-alpha |
Defold editor sha | 4f2478d053dd63a6fcaa794b994256e7b0b25038 |
Defold engine sha | 3abf70ee10dfb24e43529ff2e7ffbf1905ef5c19 |
Defold version | 1.2.130 |
GPU | Intel(R) Iris(TM) Graphics 650 |
GPU Driver | 2.1 INTEL-10.34.27 |
Java version | 1.8.0_102-b14 |
OS arch | x86_64 |
OS name | Mac OS X |
OS version | 10.13.5 |