Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

touch-input: fix app crashes on any touch input #371

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading