Skip to content

Problem with multitouch handling in gesture.lua #55

@maningame

Description

@maningame

If you tap with more than 2 fingers on the touchscreen, the following error can appears (tested on multiple android devices in google chrome browser):

[ERROR:SCRIPT]: in/gesture.lua:196: attempt to index local 'state' (a nil value)

Traceback:

{"traceback":"stack traceback:\n  in\/gesture.lua:196: in function handle_touch\n  in\/gesture.lua:249: in function handle_multi_touch\n  in\/gesture.lua:295: in function <in\/gesture.lua:283>\n  (tail call):-1: ?\n  game\/common\/tutorial\/tutorial.gui_script:227: in function <game\/common\/tutorial\/tutorial.gui_script:226>\n","source":"lua"}

I conducted a mini-investigation; the problem is in this function:

function instance.on_input(action_id, action)
	if action.touch then
		if settings.multi_touch then
			if #action.touch == 2 then
				local t1 = action.touch[1]
				local t2 = action.touch[2]
				if current_touch_count < 2 then
					multi_states[t1.id] = create_touch_state()
					multi_states[t2.id] = create_touch_state()
					t1.pressed = true
					t2.pressed = true
				end
				handle_multi_touch(t1, t2)
			end
			current_touch_count = #action.touch
			return gestures
		end
	elseif action_id == settings.action_id then
		handle_single_touch(action)
		return gestures
	end
end

The state is set only for ids 1 and 2, but if you tap with more than 2 fingers, then t1.id / t2.id can differ from 1 and 2. As a result, an error occurs in the local function handle_multi_touch(t1, t2) when calling handle_touch(t1, s1) because s1 is nil.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions