libweston: fix animation crash when a view has no output assigned

This fixes a crash in animation related code where weston
would crash in weston_view_animation_create when the
view had no output assigned.

This makes sure that animation gets created and released
immediately, so done and reset callbacks still get called
properly.

Signed-off-by: Armin Krezović <krezovic.armin@gmail.com>
[Pekka: put a '{' on the right line.]
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
diff --git a/libweston/animation.c b/libweston/animation.c
index 30b3e5d..24fc4ad 100644
--- a/libweston/animation.c
+++ b/libweston/animation.c
@@ -196,6 +196,14 @@
 		weston_compositor_schedule_repaint(compositor);
 }
 
+static void
+idle_animation_destroy(void *data)
+{
+	struct weston_view_animation *animation = data;
+
+	weston_view_animation_destroy(animation);
+}
+
 static struct weston_view_animation *
 weston_view_animation_create(struct weston_view *view,
 			     float start, float stop,
@@ -206,6 +214,8 @@
 			     void *private)
 {
 	struct weston_view_animation *animation;
+	struct weston_compositor *ec = view->surface->compositor;
+	struct wl_event_loop *loop;
 
 	animation = malloc(sizeof *animation);
 	if (!animation)
@@ -229,8 +239,14 @@
 	animation->listener.notify = handle_animation_view_destroy;
 	wl_signal_add(&view->destroy_signal, &animation->listener);
 
-	wl_list_insert(&view->output->animation_list,
-		       &animation->animation.link);
+	if (view->output) {
+		wl_list_insert(&view->output->animation_list,
+			       &animation->animation.link);
+	} else {
+		wl_list_init(&animation->animation.link);
+		loop = wl_display_get_event_loop(ec->wl_display);
+		wl_event_loop_add_idle(loop, idle_animation_destroy, animation);
+	}
 
 	return animation;
 }