Search code examples
luacoronasdk

Assertion Failed when tapping the screen too much


I am developing a game that throws bullets to the direction of tap. But when I tap too much/multiple times in the center of the player, I get the following error:

Runtime error
    assertion failed!
    stack traceback:
        [C]: in function 'assert'
        ?: in function '?'
        ?: in function '_initTween'
        ?: in function 'to'
        /Users/User/Desktop/MD/screen1.lua:61: in function </Users/User/Desktop/MD/screen1.lua:31>
        ?: in function <?:221>

But when I tap slowly, it is not throwing the error. Here is the line 61 of screen1.lua:

bullet.trans = transition.to(bullet, { time=distance/bulletSpeed, y=farY, x=farX, onComplete=nil})

Thanks for all the help!

EDIT: After adding this line:

print("Values for transition: ", bullet, distance, bulletSpeed, farY, farX)

This is the result: enter image description here

Distance and fary are both Nan.


Solution

  • How to debug a problem like this:

    As a first step towards solving this problem, I suggest you print the value of the variables involved in the call to transition.to() before the call:

    print("Values for transition: ", bullet, distance, bulletSpeed, farY, farX)
    

    It's possible something is not being set/initialized properly. It will also reveal if and when you are trying to call a transition on a nil object.

    UPDATE:

    So further investigation shows that at some point you are trying to pass NaN (From the manual: "(Not a Number is a special value used to represent undefined or unrepresentable numerical results, such as 0/0.)") as arguments to transition.to and it objects to this. You should look at your assumptions when you compute distance and farY. Could you be dividing by zero or taking the square root of a negative number somewhere?