Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Panic in unsafe fill_rect_fast #461

Closed
agersant opened this issue Apr 5, 2023 · 7 comments · Fixed by #467
Closed

[BUG] Panic in unsafe fill_rect_fast #461

agersant opened this issue Apr 5, 2023 · 7 comments · Fixed by #467
Labels
bug Something isn't working

Comments

@agersant
Copy link

agersant commented Apr 5, 2023

Describe the bug

When using Rust nightly compiler, attempting to draw a line is likely to cause a panic (depending on color / line coordinates):

thread 'main' panicked at 'misaligned pointer dereference: address must be a multiple of 0x8 but is 0x1ab590c7fd3', [redacted]\plotters-bitmap-0.3.2\src\bitmap_pixel\rgb.rs:215:29

The offending line is:

I believe the relevant Nightly change is rust-lang/rust#98112, but this seems to be a plotters bug and not a rustc regression (from my limited understanding).

To Reproduce

use plotters::prelude::*;

fn main() {
    let mut backend = BitMapBackend::new("test.png", (256, 256));
    backend.draw_line((1, 0), (100, 0), &RED).unwrap();
}

Sample project: https://github.com/agersant/plotter-panic

Version Information
Plotters 0.3.4

@agersant agersant added the bug Something isn't working label Apr 5, 2023
@nbdd0121
Copy link

nbdd0121 commented Apr 5, 2023

That code does seem very broken:

  • The transmute call is wrong, because (u64, u64, u64) does not have any layout guarantees.
  • ptr comes from *mut [u8; 24], which doesn't have the correct alignment for u64.

@pbdeuchler
Copy link
Contributor

pbdeuchler commented Apr 11, 2023

I'm hitting this as well, but only when plotting a line series with a certain number of data points... i.e. purely adding more points to the same exact line "fixes" the issue.

@noahdahlman
Copy link

noahdahlman commented Apr 17, 2023

I'm getting this as well, most of the examples I tried in the docs fail when using bitmap backend. I tried this example in a sample project and always got a panic, no issues when switching to SVG backend. Only fails on nightly (I'm using nightly-x86_64-unknown-linux-gnu ), stable works fine.

use plotters::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut backend = BitMapBackend::new("1.png", (300, 200));
    backend.draw_rect((50, 50), (200, 150), &RED, true)?;
    backend.present()?;
    Ok(())
}

@Berrysoft
Copy link
Contributor

I also trigger this issue when trying to use plotters with slint with nightly toolchain. Anyway this code is broken, because you should use write_unaligned.

@jayvdb
Copy link
Contributor

jayvdb commented Jun 1, 2023

This now occurs on stable v1.70

@Berrysoft
Copy link
Contributor

We need a new release.

@ktjd123
Copy link

ktjd123 commented Jun 8, 2023

I'm having error at blend_rect_fast 😭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants