I started out with the example code from the Readme page and from there started developing some more complex scenario involving two timers. I quickly stumbled across the issues already reported related to the addListeners method, found another problem with non-multiFire listeners (added comment in existing issue report) but then came across a much more serious issue that crashes the executing program with an exception.
Per readme, I figured I can kill all existing timers with mgr.resetContext() from within a callback method.
The problem is that as part of the mgr.resetContext() method, the existing listener objects get deleted, while start_blinking() is called FROM a listener object. Once the callback method, here start_blinking, has completed the handleTimerEvent() still accesses member variables of the listener object like multiFire and even calls the non-static method setupListener() on a deleted object. Per CPP spec, this is undefined behavior. During my experiments I see an exception with subsequent termination of the program.
My background is managed languages (C#, JS, Java) so I'm still trying to wrap my head around this, trying to figure out how this chicken-egg problem can be avoided. I guess the listener deletion would have to be deferred until the performTriggerAction method has completed.
In the meantime, do NOT use the construct that is shown in the Readme.
I started out with the example code from the Readme page and from there started developing some more complex scenario involving two timers. I quickly stumbled across the issues already reported related to the
addListeners
method, found another problem with non-multiFire listeners (added comment in existing issue report) but then came across a much more serious issue that crashes the executing program with an exception.Per readme, I figured I can kill all existing timers with
mgr.resetContext()
from within a callback method.The problem is that as part of the
mgr.resetContext()
method, the existing listener objects get deleted, whilestart_blinking()
is called FROM a listener object. Once the callback method, herestart_blinking
, has completed thehandleTimerEvent()
still accesses member variables of the listener object likemultiFire
and even calls the non-static methodsetupListener()
on a deleted object. Per CPP spec, this is undefined behavior. During my experiments I see an exception with subsequent termination of the program.My background is managed languages (C#, JS, Java) so I'm still trying to wrap my head around this, trying to figure out how this chicken-egg problem can be avoided. I guess the listener deletion would have to be deferred until the
performTriggerAction
method has completed.In the meantime, do NOT use the construct that is shown in the Readme.