Bug with timer.performWithDelay?

Hello,

I’m trying to fix a bug I found in my code, its actually pretty weird.

I cant reproduce the behavior in a sample as I get it only in my complex environment now.

I would like to ask: what kind of lua code can cause a timer from not executing its onComplete function?

print(system.getTimer(), "beforeTimer") timer.performWithDelay(1, function() print(system.getTimer(), "afterTimer") end)

This is a simple example of the code I execute, you would expect the afterTimer should always get executed, but it is not… Somehow some other code in my projects stops it I think, because it only happens when I button bash my analog stick in the game to walk the player around.

The output I get is the following:

10494.218 beforeTimer

10510.503 afterTimer

10776.975 beforeTimer

10794.729 afterTimer

11045.712 beforeTimer

11062.548 afterTimer

11376.585 beforeTimer

11393.385 afterTimer

11668.887 beforeTimer

11685.302 afterTimer

12213.489 beforeTimer

It stops at beforeTimer, but it never executes the afterTimer print after that. I do not cancel any timers in my code, and when I attach a runtimeListener on creation that prints the timer, it shows me the timer stays in memory (without any _paused or _cancelled state), the function is just not executed.

What can cause this to happen? Too much load on CPU? 

PS. The bug does not occur on my iPhone device, only in simulator

Hi @pouwelsjochem8,

You’ll probably need to show more supporting code around this, i.e. whatever you’re doing with the “analog stick” and how you’re detecting it.

Thanks,

Brent

I’m not able to share code at the moment, and if I could it would be hard to show everything whats happening, ill try to explain the flow

I have an enterFrame function that sends the direction to my playerObject, it reads the direction of my analogStick, so in fact it just sends a direction string or nil to my player every frame

My player receives the direction and is going to try moving to that direction, the move takes about 250ms and while it is moving it ignores other inputs from the analog stick, when it knows its done moving, it executes a function after a 1frame delay (this is the code I mentioned, but I simplified it above by only using prints)

Its hard to explain exactly whats happening as its pretty complex, but the real question is, how could this even happen? That a timer does not execute its anonymous function without being paused or cancelled? It just skips it somehow :frowning:

Hi @pouwelsjochem8,

Is this an actual analog stick, or a “virtual on screen” UI? If the former, why not just use inputDevice methods instead of all the weird timer stuff?

Brent

Hi Brent

Well I used the timer because of limitations in the MTE engine, the onComplete method passed in the params executed itself too early, it executed in the same application cycle as the object:translate() method, I needed it to execute 1 application cycle later

But I changed the sourcecode of the MTE engine now to have an onAlmostComplete and an onComplete param, so no more weird stuff with timers, and it works! Thanks for your help!

Hi Brent

Well I used the timer because of limitations in the MTE engine, the onComplete method passed in the params executed itself too early, it executed in the same application cycle as the object:translate() method, I needed it to execute 1 application cycle later

But I changed the sourcecode of the MTE engine now to have an onAlmostComplete and an onComplete param, so no more weird stuff with timers, and it works! Thanks for your help!

Hi @pouwelsjochem8,

You’ll probably need to show more supporting code around this, i.e. whatever you’re doing with the “analog stick” and how you’re detecting it.

Thanks,

Brent

I’m not able to share code at the moment, and if I could it would be hard to show everything whats happening, ill try to explain the flow

I have an enterFrame function that sends the direction to my playerObject, it reads the direction of my analogStick, so in fact it just sends a direction string or nil to my player every frame

My player receives the direction and is going to try moving to that direction, the move takes about 250ms and while it is moving it ignores other inputs from the analog stick, when it knows its done moving, it executes a function after a 1frame delay (this is the code I mentioned, but I simplified it above by only using prints)

Its hard to explain exactly whats happening as its pretty complex, but the real question is, how could this even happen? That a timer does not execute its anonymous function without being paused or cancelled? It just skips it somehow :frowning:

Hi @pouwelsjochem8,

Is this an actual analog stick, or a “virtual on screen” UI? If the former, why not just use inputDevice methods instead of all the weird timer stuff?

Brent

Hi Brent

Well I used the timer because of limitations in the MTE engine, the onComplete method passed in the params executed itself too early, it executed in the same application cycle as the object:translate() method, I needed it to execute 1 application cycle later

But I changed the sourcecode of the MTE engine now to have an onAlmostComplete and an onComplete param, so no more weird stuff with timers, and it works! Thanks for your help!

Hi Brent

Well I used the timer because of limitations in the MTE engine, the onComplete method passed in the params executed itself too early, it executed in the same application cycle as the object:translate() method, I needed it to execute 1 application cycle later

But I changed the sourcecode of the MTE engine now to have an onAlmostComplete and an onComplete param, so no more weird stuff with timers, and it works! Thanks for your help!