@@ -137,6 +137,13 @@ void FlutterELinuxView::OnTouchDown(uint32_t time,
137137 int32_t id,
138138 double x,
139139 double y) {
140+ // Increase device-id to avoid
141+ // "FML_DCHECK(states_.find(pointer_data.device) == states_.end());"
142+ // exception in flutter/engine.
143+ // This is because "device-id = 0" is used for mouse inputs.
144+ // See engine/lib/ui/window/pointer_data_packet_converter.cc
145+ id += 1 ;
146+
140147 auto trimmed_xy = GetPointerRotation (x, y);
141148 auto * point = GgeTouchPoint (id);
142149 if (!point) {
@@ -163,10 +170,25 @@ void FlutterELinuxView::OnTouchDown(uint32_t time,
163170}
164171
165172void FlutterELinuxView::OnTouchUp (uint32_t time, int32_t id) {
173+ // Increase device-id to avoid
174+ // "FML_DCHECK(states_.find(pointer_data.device) == states_.end());"
175+ // exception in flutter/engine.
176+ // This is because "device-id = 0" is used for mouse inputs.
177+ // See engine/lib/ui/window/pointer_data_packet_converter.cc
178+ id += 1 ;
179+
166180 auto * point = GgeTouchPoint (id);
167181 if (!point) {
168182 return ;
169183 }
184+
185+ // Makes sure we have an existing touch pointer in down state to
186+ // avoid "FML_DCHECK(iter != states_.end())" exception in flutter/engine.
187+ // See engine/lib/ui/window/pointer_data_packet_converter.cc
188+ if (point->event_mask != TouchEvent::kDown &&
189+ point->event_mask != TouchEvent::kMotion ) {
190+ return ;
191+ }
170192 point->event_mask = TouchEvent::kUp ;
171193
172194 FlutterPointerEvent event = {
@@ -189,11 +211,26 @@ void FlutterELinuxView::OnTouchMotion(uint32_t time,
189211 int32_t id,
190212 double x,
191213 double y) {
214+ // Increase device-id to avoid avoid
215+ // "FML_DCHECK(states_.find(pointer_data.device) == states_.end());"
216+ // exception in flutter/engine.
217+ // This is because "device-id = 0" is used for mouse inputs.
218+ // See engine/lib/ui/window/pointer_data_packet_converter.cc
219+ id += 1 ;
220+
192221 auto trimmed_xy = GetPointerRotation (x, y);
193222 auto * point = GgeTouchPoint (id);
194223 if (!point) {
195224 return ;
196225 }
226+
227+ // Makes sure we have an existing touch pointer in down state to
228+ // avoid "FML_DCHECK(iter != states_.end())" exception in flutter/engine.
229+ // See engine/lib/ui/window/pointer_data_packet_converter.cc
230+ if (point->event_mask != TouchEvent::kDown &&
231+ point->event_mask != TouchEvent::kMotion ) {
232+ return ;
233+ }
197234 point->event_mask = TouchEvent::kMotion ;
198235 point->x = trimmed_xy.first ;
199236 point->y = trimmed_xy.second ;
0 commit comments