From 3e39dabeac181ff4afce810ec985fbd9a7685680 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 13 Apr 2023 11:20:22 +1000 Subject: [PATCH] tools/demo-server: check if we have a touch before sending one If the client was disconnected, the returned touch is NULL. Check for that instead of blindly assuming we can send the touch. --- tools/eis-demo-server.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/tools/eis-demo-server.c b/tools/eis-demo-server.c index a2b284b..b422207 100644 --- a/tools/eis-demo-server.c +++ b/tools/eis-demo-server.c @@ -741,21 +741,27 @@ int main(int argc, char **argv) switch (counter++ % 5) { case 0: - colorprint("sending touch down event\n"); touch = eis_device_touch_new(touchscreen); - eis_touch_down(touch, 100 + ++x, 200 - ++y); - eis_device_frame(touchscreen, now); - democlient->touch = touch; + if (touch) { /* NULL if client was disconnected internally already */ + colorprint("sending touch down event\n"); + eis_touch_down(touch, 100 + ++x, 200 - ++y); + eis_device_frame(touchscreen, now); + democlient->touch = touch; + } break; case 4: - colorprint("sending touch down event\n"); - eis_touch_up(touch); - eis_device_frame(touchscreen, now); - democlient->touch = eis_touch_unref(touch); + if (touch) { + colorprint("sending touch down event\n"); + eis_touch_up(touch); + eis_device_frame(touchscreen, now); + democlient->touch = eis_touch_unref(touch); + } break; default: - eis_touch_motion(touch, 100 + ++x, 200 - ++y); - eis_device_frame(touchscreen, now); + if (touch) { + eis_touch_motion(touch, 100 + ++x, 200 - ++y); + eis_device_frame(touchscreen, now); + } break; }