Invalid touch index

Create issue
Issue #60 resolved
Martin Felis repo owner created an issue

A simple game can cause LÖVE to crash which then reports the error "Invalid touch index".

    function love.update(dt)
       for i = 1,love.touch.getTouchCount() do
          id, x, y, pressure = love.touch.getTouch(i)
          sleep(.1) -- wait a tenth of a second

    local clock = os.clock
    function sleep(n)
      local t0 = clock()
      while clock() - t0 <= n do end

(See also the attached .love)

Comments (5)

  1. Pablo Ariel Mayobre

    Could be solved by storing the touch table every time that an update begins. Currently I do that and works quite right, never had problems.

    But is a workaround and not a real fix thught

  2. Martin Felis reporter

    I think it actually is a fix as one cannot guarantee that a finger stays in contact with the display for the duration of the update call. Problem is just that this involves introducing new logic in the official LÖVE. So it will take a little longer to fix.

  3. miko

    Its a bug in programming logic, not in the love2d itself. The same would apply to keyboard/mouse/gamepad. I would not "fix" that. In most cases, the solution works OK. For situation when the loop can take longer (and that is the problem), the state of the current touch position can be stored in a table before entering the long-running loop. But then you risk that your data will be staled (the finges is not there yet).

    So the real solution is to process events as quick as possible (detecting finger position and store it), and then do longer lasting logic. So basically split update() into update_events() and update_logic().

  4. Alex Szpakowski

    I fixed the issue (I hope) in the latest commits to the mobile-common branch of LÖVE.

    Unfortunately I think the cause of the bug affects love.keyboard, love.joystick, and love.mouse as well, but the effects should be much less noticeable on those modules than love.touch.

  5. Log in to comment