Implement workaround to prevent panics with empty scenes
diff --git a/vello/src/scene.rs b/vello/src/scene.rs
index 103e9b2..064b750 100644
--- a/vello/src/scene.rs
+++ b/vello/src/scene.rs
@@ -25,7 +25,7 @@
///
/// A Scene stores a sequence of drawing commands, their context, and the
/// associated resources, which can later be rendered.
-#[derive(Clone, Default)]
+#[derive(Clone)]
pub struct Scene {
encoding: Encoding,
#[cfg(feature = "bump_estimate")]
@@ -33,6 +33,31 @@
}
static_assertions::assert_impl_all!(Scene: Send, Sync);
+impl Default for Scene {
+ fn default() -> Self {
+ let mut scene = Self {
+ encoding: Default::default(),
+ #[cfg(feature = "bump_estimate")]
+ estimator: Default::default(),
+ };
+
+ // FIXME - `Render` panics when given an empty scene
+ // See https://github.com/linebender/vello/issues/291
+ // Until that panic is fixed, this workaround makes it
+ // so scenes are never empty by default.
+ let empty_path = Rect::ZERO;
+ scene.fill(
+ Fill::NonZero,
+ Affine::IDENTITY,
+ Color::TRANSPARENT,
+ None,
+ &empty_path,
+ );
+
+ scene
+ }
+}
+
impl Scene {
/// Creates a new scene.
pub fn new() -> Self {