Skip to content

[BUG] thread 'main' panicked: The font implementation is unable to draw text #695

Open
@Supermarcel10

Description

@Supermarcel10

Describe the bug
Plotters panics when attempting to draw a graph. This only happens with the BitMapBackend.

The last stacktrace entry relating to plotters is:

panic!("The font implementation is unable to draw text");

Stacktrace

export RUST_BACKTRACE=full && cargo run
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/x86_64-unknown-linux-gnu/debug/plotters_bug_repr`

thread 'main' panicked at /home/marcel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/plotters-0.3.7/src/style/font/mod.rs:75:9:
The font implementation is unable to draw text
stack backtrace:
   0:     0x5e531d2e5320 - std::backtrace_rs::backtrace::libunwind::trace::h2b8934d68a0c74cb
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/../../backtrace/src/backtrace/libunwind.rs:117:9
   1:     0x5e531d2e5320 - std::backtrace_rs::backtrace::trace_unsynchronized::h72d137991fa6eab8
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/../../backtrace/src/backtrace/mod.rs:66:14
   2:     0x5e531d2e5320 - std::sys::backtrace::_print_fmt::h3e831e32e6da920b
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/sys/backtrace.rs:66:9
   3:     0x5e531d2e5320 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h6d42cc84fc840290
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/sys/backtrace.rs:39:26
   4:     0x5e531d307f33 - core::fmt::rt::Argument::fmt::h7239af9e2199f2a8
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/core/src/fmt/rt.rs:177:76
   5:     0x5e531d307f33 - core::fmt::write::h5af61a909e3ec64d
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/core/src/fmt/mod.rs:1449:21
   6:     0x5e531d2e29a3 - std::io::Write::write_fmt::h5a7b54aa6e4a315d
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/io/mod.rs:1890:15
   7:     0x5e531d2e5172 - std::sys::backtrace::BacktraceLock::print::h555579e7396c26ac
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/sys/backtrace.rs:42:9
   8:     0x5e531d2e60cf - std::panicking::default_hook::{{closure}}::h9128866118196224
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/panicking.rs:298:22
   9:     0x5e531d2e5f3a - std::panicking::default_hook::h52e9e7314e0255f6
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/panicking.rs:325:9
  10:     0x5e531d2e6ab2 - std::panicking::rust_panic_with_hook::h541791bcc774ef34
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/panicking.rs:831:13
  11:     0x5e531d2e698c - std::panicking::begin_panic::{{closure}}::h4d8ebad7787f6bf4
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/panicking.rs:768:9
  12:     0x5e531d2e5829 - std::sys::backtrace::__rust_end_short_backtrace::h52f9c099bc75a494
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/sys/backtrace.rs:168:18
  13:     0x5e531d2e6892 - std::panicking::begin_panic::h815831b19d7a8c5e
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/panicking.rs:767:5
  14:     0x5e531d23466c - plotters::style::font::FontData::draw::h5104eeb7856e0898
                               at /home/marcel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/plotters-0.3.7/src/style/font/mod.rs:75:9
  15:     0x5e531d2098c8 - plotters::style::font::font_desc::FontDesc::draw::hea104abedb9ff10b
                               at /home/marcel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/plotters-0.3.7/src/style/font/font_desc.rs:168:29
  16:     0x5e531d215936 - <plotters::style::text::TextStyle as plotters_backend::text::BackendTextStyle>::draw::h2043f33e3fea25fb
                               at /home/marcel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/plotters-0.3.7/src/style/text.rs:322:9
  17:     0x5e531d23ffe8 - plotters_backend::DrawingBackend::draw_text::hf0d8701ca0003126
                               at /home/marcel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/plotters-backend-0.3.7/src/lib.rs:250:30
  18:     0x5e531d225f40 - plotters::drawing::area::DrawingArea<DB,plotters::coord::Shift>::titled::{{closure}}::h376f60996643ae21
                               at /home/marcel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/plotters-0.3.7/src/drawing/area.rs:496:13
  19:     0x5e531d223ea1 - plotters::drawing::area::DrawingArea<DB,CT>::backend_ops::hf0e22e59c9c44b60
                               at /home/marcel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/plotters-0.3.7/src/drawing/area.rs:282:13
  20:     0x5e531d225b76 - plotters::drawing::area::DrawingArea<DB,plotters::coord::Shift>::titled::hfebada1ec95eef11
                               at /home/marcel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/plotters-0.3.7/src/drawing/area.rs:495:9
  21:     0x5e531d1fd03b - plotters::chart::builder::ChartBuilder<DB>::build_cartesian_2d::h3d7c26199e0e7d09
                               at /home/marcel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/plotters-0.3.7/src/chart/builder.rs:332:28
  22:     0x5e531d21b99a - plotters_bug_repr::main::h335f1e321a576015
                               at /home/marcel/RustroverProjects/plotters_but_repr/src/main.rs:5:21
  23:     0x5e531d22a79b - core::ops::function::FnOnce::call_once::h8f0ea04a2e21af03
                               at /home/marcel/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
  24:     0x5e531d21563e - std::sys::backtrace::__rust_begin_short_backtrace::h127519f7afca4ae8
                               at /home/marcel/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:152:18
  25:     0x5e531d210b51 - std::rt::lang_start::{{closure}}::h2e737a3507f4358b
                               at /home/marcel/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:199:18
  26:     0x5e531d2dfdc0 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h11180d46f4bd77b0
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/core/src/ops/function.rs:284:13
  27:     0x5e531d2dfdc0 - std::panicking::try::do_call::hd4e634b5516dff98
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/panicking.rs:587:40
  28:     0x5e531d2dfdc0 - std::panicking::try::hb26f372c4276d7b4
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/panicking.rs:550:19
  29:     0x5e531d2dfdc0 - std::panic::catch_unwind::hcff84ccd1cc2f0a5
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/panic.rs:358:14
  30:     0x5e531d2dfdc0 - std::rt::lang_start_internal::{{closure}}::h7f5cb21b2420f132
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/rt.rs:168:24
  31:     0x5e531d2dfdc0 - std::panicking::try::do_call::he996326bc7b05062
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/panicking.rs:587:40
  32:     0x5e531d2dfdc0 - std::panicking::try::h17585bee78ecbda5
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/panicking.rs:550:19
  33:     0x5e531d2dfdc0 - std::panic::catch_unwind::h366ac34033c6e5d6
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/panic.rs:358:14
  34:     0x5e531d2dfdc0 - std::rt::lang_start_internal::h15895544e2012228
                               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/rt.rs:164:5
  35:     0x5e531d210b37 - std::rt::lang_start::h1d87ce8e1bdb935d
                               at /home/marcel/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:198:5
  36:     0x5e531d21c05e - main
  37:     0x764cd221d27e - __libc_start_call_main
  38:     0x764cd221d339 - __libc_start_main_alias_2
  39:     0x5e531d1ee8c5 - _start
  40:                0x0 - <unknown>

To Reproduce
Using the Plotters.rs Quick Start example:

Cargo.toml

[package]
name = "plotters_bug_repr"
version = "0.1.0"
edition = "2024"

[dependencies]
plotters = { version = "0.3.7", default-features = false, features = ["svg_backend", "bitmap_backend", "bitmap_encoder", "line_series"] }

src/main.rs

use plotters::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let root = BitMapBackend::new("0.png", (640, 480)).into_drawing_area();
    root.fill(&WHITE)?;
    let mut chart = ChartBuilder::on(&root)
        .caption("y=x^2", ("sans-serif", 50).into_font())
        .margin(5)
        .x_label_area_size(30)
        .y_label_area_size(30)
        .build_cartesian_2d(-1f32..1f32, -0.1f32..1f32)?;

    chart.configure_mesh().draw()?;

    chart
        .draw_series(LineSeries::new(
            (-50..=50).map(|x| x as f32 / 50.0).map(|x| (x, x * x)),
            &RED,
        ))?
        .label("y = x^2")
        .legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &RED));

    chart
        .configure_series_labels()
        .background_style(&WHITE.mix(0.8))
        .border_style(&BLACK)
        .draw()?;

    root.present()?;

    Ok(())
}

With the following changes, this example compiles and runs generating a graph:

- let root = BitMapBackend::new("0.png", (640, 480)).into_drawing_area();
+ let root = SVGBackend::new("0.svg", (640, 480)).into_drawing_area();

Version Information
Plotters.rs version 0.3.7
rustc version 1.86.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions