plotters icon indicating copy to clipboard operation
plotters copied to clipboard

[BUG] unsafe preconditions violated

Open HyperCodec opened this issue 10 months ago • 12 comments

Describe the bug I start to get this error on build_cartesian_2d:

thread 'main' panicked at library/core/src/panicking.rs:215:5:
unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`
stack backtrace:
   0: rust_begin_unwind
             at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_nounwind_fmt::runtime
             at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/core/src/panicking.rs:110:18
   2: core::panicking::panic_nounwind_fmt
             at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/core/src/panicking.rs:120:5
   3: core::panicking::panic_nounwind
             at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/core/src/panicking.rs:215:5
   4: core::slice::raw::from_raw_parts::precondition_check
             at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/core/src/ub_checks.rs:66:21
   5: core::slice::raw::from_raw_parts
             at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/core/src/slice/raw.rs:96:9
   6: font_kit::loaders::freetype::Font::rasterize_glyph
             at /home/codespace/.cargo/registry/src/index.crates.io-6f17d22bba15001f/font-kit-0.11.0/src/loaders/freetype.rs:847:26
   7: <plotters::style::font::ttf::FontDataInternal as plotters::style::font::FontData>::draw
             at /home/codespace/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plotters-0.3.5/src/style/font/ttf.rs:265:26
   8: plotters::style::font::font_desc::FontDesc::draw
             at /home/codespace/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plotters-0.3.5/src/style/font/font_desc.rs:168:29
   9: <plotters::style::text::TextStyle as plotters_backend::text::BackendTextStyle>::draw
             at /home/codespace/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plotters-0.3.5/src/style/text.rs:322:9
  10: plotters_backend::DrawingBackend::draw_text
             at /home/codespace/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plotters-backend-0.3.5/src/lib.rs:250:15
  11: plotters::drawing::area::DrawingArea<DB,plotters::coord::Shift>::titled::{{closure}}
             at /home/codespace/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plotters-0.3.5/src/drawing/area.rs:496:13
  12: plotters::drawing::area::DrawingArea<DB,CT>::backend_ops
             at /home/codespace/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plotters-0.3.5/src/drawing/area.rs:282:13
  13: plotters::drawing::area::DrawingArea<DB,plotters::coord::Shift>::titled
             at /home/codespace/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plotters-0.3.5/src/drawing/area.rs:495:9
  14: plotters::chart::builder::ChartBuilder<DB>::build_cartesian_2d
             at /home/codespace/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plotters-0.3.5/src/chart/builder.rs:332:28
  15: plot::main
             at ./examples/plot.rs:93:21
  16: core::ops::function::FnOnce::call_once
             at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread caused non-unwinding panic. aborting.
Aborted (core dumped)

To Reproduce Here's everything I have that is related to this crate:

let root = BitMapBackend::new(OUTPUT_FILE_NAME, (640, 480)).into_drawing_area();
root.fill(&WHITE)?;

let mut chart = ChartBuilder::on(&root)
      .caption("agent fitness values per generation", ("sans-serif", 50).into_font())
      .margin(5)
      .x_label_area_size(30)
      .y_label_area_size(30)
      .build_cartesian_2d(0usize..100, 0f32..200.0)?;

chart.configure_mesh().draw()?;

let data: Vec<_> = Arc::into_inner(performance_stats).unwrap().into_inner().unwrap()
      .into_iter()
      .enumerate()
      .collect();
let highs = data
      .iter()
      .map(|(i, PerformanceStats { high, .. })| (*i, *high));

let medians = data
      .iter()
      .map(|(i, PerformanceStats { median, .. })| (*i, *median));

let lows = data
     .iter()
     .map(|(i, PerformanceStats { low, .. })| (*i, *low));

chart
    .draw_series(LineSeries::new(highs, &GREEN))?
    .label("high");

chart
    .draw_series(LineSeries::new(medians, &YELLOW))?
    .label("median");

chart
    .draw_series(LineSeries::new(lows, &RED))?
    .label("low");

root.present()?;

Version Information plotters = "0.3.5"

HyperCodec avatar Apr 16 '24 18:04 HyperCodec