Skip to content

Commit

Permalink
touch-input: fix app crashes on any touch input (#371)
Browse files Browse the repository at this point in the history
This change adds a touch pointer state check and increase device id from touch inputs to fix sony/flutter-elinux#126.

Signed-off-by: Hidenori Matsubayashi <Hidenori.Matsubayashi@gmail.com>
  • Loading branch information
HidenoriMatsubayashi authored Aug 16, 2023
1 parent d496f1f commit f177e10
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ void FlutterELinuxView::OnTouchDown(uint32_t time,
int32_t id,
double x,
double y) {
// Increase device-id to avoid
// "FML_DCHECK(states_.find(pointer_data.device) == states_.end());"
// exception in flutter/engine.
// This is because "device-id = 0" is used for mouse inputs.
// See engine/lib/ui/window/pointer_data_packet_converter.cc
id += 1;

auto trimmed_xy = GetPointerRotation(x, y);
auto* point = GgeTouchPoint(id);
if (!point) {
Expand All @@ -163,10 +170,25 @@ void FlutterELinuxView::OnTouchDown(uint32_t time,
}

void FlutterELinuxView::OnTouchUp(uint32_t time, int32_t id) {
// Increase device-id to avoid
// "FML_DCHECK(states_.find(pointer_data.device) == states_.end());"
// exception in flutter/engine.
// This is because "device-id = 0" is used for mouse inputs.
// See engine/lib/ui/window/pointer_data_packet_converter.cc
id += 1;

auto* point = GgeTouchPoint(id);
if (!point) {
return;
}

// Makes sure we have an existing touch pointer in down state to
// avoid "FML_DCHECK(iter != states_.end())" exception in flutter/engine.
// See engine/lib/ui/window/pointer_data_packet_converter.cc
if (point->event_mask != TouchEvent::kDown &&
point->event_mask != TouchEvent::kMotion) {
return;
}
point->event_mask = TouchEvent::kUp;

FlutterPointerEvent event = {
Expand All @@ -189,11 +211,26 @@ void FlutterELinuxView::OnTouchMotion(uint32_t time,
int32_t id,
double x,
double y) {
// Increase device-id to avoid avoid
// "FML_DCHECK(states_.find(pointer_data.device) == states_.end());"
// exception in flutter/engine.
// This is because "device-id = 0" is used for mouse inputs.
// See engine/lib/ui/window/pointer_data_packet_converter.cc
id += 1;

auto trimmed_xy = GetPointerRotation(x, y);
auto* point = GgeTouchPoint(id);
if (!point) {
return;
}

// Makes sure we have an existing touch pointer in down state to
// avoid "FML_DCHECK(iter != states_.end())" exception in flutter/engine.
// See engine/lib/ui/window/pointer_data_packet_converter.cc
if (point->event_mask != TouchEvent::kDown &&
point->event_mask != TouchEvent::kMotion) {
return;
}
point->event_mask = TouchEvent::kMotion;
point->x = trimmed_xy.first;
point->y = trimmed_xy.second;
Expand Down

0 comments on commit f177e10

Please sign in to comment.