From 26d8ad7479c04ba142460770fa577ea2a539a8b2 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 26 Apr 2012 13:23:29 +0100 Subject: [PATCH] Be resilient in case there is no device manager It's possible to run Clutter with the 'null' input backend, which means that clutter_device_manager_get_default() may return NULL. In the future we may add a default dummy device manager, but right now it's safer to just add a simple NULL check in the places where we ask for the device manager. --- clutter/clutter-main.c | 8 ++++++++ clutter/gdk/clutter-event-gdk.c | 5 ++++- clutter/osx/clutter-event-osx.c | 13 +++++++++---- clutter/win32/clutter-event-win32.c | 3 +++ clutter/x11/clutter-backend-x11.c | 2 ++ clutter/x11/clutter-stage-x11.c | 14 +++++++++----- 6 files changed, 35 insertions(+), 10 deletions(-) diff --git a/clutter/clutter-main.c b/clutter/clutter-main.c index a36519579..be07b7f42 100644 --- a/clutter/clutter-main.c +++ b/clutter/clutter-main.c @@ -2981,6 +2981,9 @@ clutter_grab_pointer_for_device (ClutterActor *actor, } manager = clutter_device_manager_get_default (); + if (manager == NULL) + return; + dev = clutter_device_manager_get_device (manager, id_); if (dev == NULL) return; @@ -3025,6 +3028,9 @@ clutter_ungrab_pointer_for_device (gint id_) ClutterInputDevice *device; manager = clutter_device_manager_get_default (); + if (manager == NULL) + return; + device = clutter_device_manager_get_device (manager, id_); if (device != NULL) clutter_input_device_ungrab (device); @@ -3293,6 +3299,8 @@ clutter_get_input_device_for_id (gint id_) ClutterDeviceManager *manager; manager = clutter_device_manager_get_default (); + if (manager == NULL) + return NULL; return clutter_device_manager_get_device (manager, id_); } diff --git a/clutter/gdk/clutter-event-gdk.c b/clutter/gdk/clutter-event-gdk.c index 3276996b7..c01461b09 100644 --- a/clutter/gdk/clutter-event-gdk.c +++ b/clutter/gdk/clutter-event-gdk.c @@ -78,9 +78,12 @@ clutter_gdk_handle_event (GdkEvent *gdk_event) if (gdk_event->any.window == NULL) return GDK_FILTER_CONTINUE; + device_manager = clutter_device_manager_get_default (); + if (G_UNLIKELY (device_manager == NULL)) + return GDK_FILTER_CONTINUE; + backend_gdk = CLUTTER_BACKEND_GDK (backend); stage = clutter_gdk_get_stage_from_window (gdk_event->any.window); - device_manager = clutter_device_manager_get_default (); gdk_device = gdk_event_get_device (gdk_event); if (gdk_device != NULL) diff --git a/clutter/osx/clutter-event-osx.c b/clutter/osx/clutter-event-osx.c index 6ba14f607..386ef7e4e 100644 --- a/clutter/osx/clutter-event-osx.c +++ b/clutter/osx/clutter-event-osx.c @@ -306,14 +306,19 @@ clutter_event_osx_translate (NSEvent *nsevent, ClutterEvent *event) { ClutterDeviceManagerOSX *manager_osx; + ClutterDeviceManager *manager; ClutterStageOSX *stage_osx; ClutterStageWindow *impl; ClutterStage *stage; - stage = event->any.stage; - impl = _clutter_stage_get_window (event->any.stage); - stage_osx = CLUTTER_STAGE_OSX (impl); - manager_osx = CLUTTER_DEVICE_MANAGER_OSX (clutter_device_manager_get_default ()); + manager = clutter_device_manager_get_default (); + if (manager == NULL) + return FALSE; + + stage = event->any.stage; + impl = _clutter_stage_get_window (event->any.stage); + stage_osx = CLUTTER_STAGE_OSX (impl); + manager_osx = CLUTTER_DEVICE_MANAGER_OSX (manager); event->any.time = [nsevent clutterTime]; diff --git a/clutter/win32/clutter-event-win32.c b/clutter/win32/clutter-event-win32.c index 7274c8c4d..eab1991c0 100644 --- a/clutter/win32/clutter-event-win32.c +++ b/clutter/win32/clutter-event-win32.c @@ -375,6 +375,9 @@ clutter_win32_handle_event (const MSG *msg) return TRUE; manager = clutter_device_manager_get_default (); + if (manager == NULL) + return FALSE; + core_pointer = clutter_device_manager_get_core_device (manager, CLUTTER_POINTER_DEVICE); core_keyboard = diff --git a/clutter/x11/clutter-backend-x11.c b/clutter/x11/clutter-backend-x11.c index be02d340b..52a551d41 100644 --- a/clutter/x11/clutter-backend-x11.c +++ b/clutter/x11/clutter-backend-x11.c @@ -1185,6 +1185,8 @@ clutter_x11_get_input_devices (void) ClutterDeviceManager *manager; manager = clutter_device_manager_get_default (); + if (manager == NULL) + return NULL; return clutter_device_manager_peek_devices (manager); } diff --git a/clutter/x11/clutter-stage-x11.c b/clutter/x11/clutter-stage-x11.c index 45a6fa2ea..ffa2fb5b7 100644 --- a/clutter/x11/clutter-stage-x11.c +++ b/clutter/x11/clutter-stage-x11.c @@ -652,12 +652,16 @@ clutter_stage_x11_realize (ClutterStageWindow *stage_window) * the event mask we passed to XSelectInput as the template */ device_manager = clutter_device_manager_get_default (); - _clutter_device_manager_select_stage_events (device_manager, - stage_cogl->wrapper, - event_flags); + if (G_UNLIKELY (device_manager != NULL)) + { + _clutter_device_manager_select_stage_events (device_manager, + stage_cogl->wrapper, + event_flags); - g_signal_connect (device_manager, "device-added", - G_CALLBACK (stage_events_device_added), stage_window); + g_signal_connect (device_manager, "device-added", + G_CALLBACK (stage_events_device_added), + stage_window); + } clutter_stage_x11_fix_window_size (stage_x11, stage_x11->xwin_width,