vl-convert: Segmentation fault on subsequent conversions

Hello, thank you for this fantastic package!

The following modified example from vl-convert-rs results in a segfault:

use vl_convert_rs::converter::VlOpts;
use vl_convert_rs::{VlConverter, VlVersion};

#[tokio::main]
async fn main() {
    let vl_spec: serde_json::Value = serde_json::from_str(
        r#"
{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {"url": "data/movies.json"},
  "mark": "circle",
  "encoding": {
    "x": {
      "bin": {"maxbins": 10},
      "field": "IMDB Rating"
    },
    "y": {
      "bin": {"maxbins": 10},
      "field": "Rotten Tomatoes Rating"
    },
    "size": {"aggregate": "count"}
  }
}   "#,
    )
    .unwrap();


    println!("{}", convert(vl_spec.clone()).await);
    println!("{}", convert(vl_spec.clone()).await)
}

async fn convert(vl_spec: serde_json::Value) -> String {
  let mut converter = VlConverter::new();

  converter
      .vegalite_to_svg(
          vl_spec,
          VlOpts {
              vl_version: VlVersion::v5_8,
              ..Default::default()
          },
      )
      .await
      .expect("Failed to perform Vega-Lite to Vega conversion")
}

Note a separate converter created for each conversion. If we change it to reuse the same converter it no longer segfaults.

I can reproduce the segfault on x86_64 Ubuntu Linux, running the example directly against vl-convert-rs main.

About this issue

Most upvoted comments

png export works by converting to SVG first, and then converting from svg to PNG with the pure rust resvg library. So it sounds like the original error inside deno/v8 isn’t happening on MacOS. Thanks for giving it a try! I’ll try to repro on circleci soon.

@charlesfsl you can try this:

Details
use vl_convert_rs::converter::VlOpts;
use vl_convert_rs::{VlConverter, VlVersion};

#[tokio::main]
async fn main() {
    let vl_spec: serde_json::Value = serde_json::from_str(
        r#"
{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {"url": "data/movies.json"},
  "mark": "circle",
  "encoding": {
    "x": {
      "bin": {"maxbins": 10},
      "field": "IMDB Rating"
    },
    "y": {
      "bin": {"maxbins": 10},
      "field": "Rotten Tomatoes Rating"
    },
    "size": {"aggregate": "count"}
  }
}   "#,
    )
    .unwrap();

    println!("{}", convert(vl_spec.clone()).await.len());
    println!("{}", convert(vl_spec.clone()).await.len())
}

async fn convert(vl_spec: serde_json::Value) -> Vec<u8> {
    let mut converter = VlConverter::new();

    converter
        .vegalite_to_png(
            vl_spec,
            VlOpts {
                vl_version: VlVersion::v5_8,
                ..Default::default()
            },
            None,
            None
        )
        .await
        .expect("Failed to perform Vega-Lite to Vega conversion")
}

I couldn’t reproduce on mac, but maybe you will have more luck 😃

No problem, @jonmmease . I’ll give that a go, probably tonight, and let you know.