caemor / epd-waveshare

Drivers for various EPDs from Waveshare
ISC License
217 stars 131 forks source link

cannot compile epd-waveshare (overflow error) #151

Closed tippfehlr closed 9 months ago

tippfehlr commented 1 year ago

Disabling default features removes the error.

$ cargo build
    Updating crates.io index
   Compiling epd-waveshare v0.5.0
error[E0080]: evaluation of constant value failed
  --> /home/jonathan/.cargo/registry/src/github.com-1ecc6299db9ec823/epd-waveshare-0.5.0/src/epd4in2/graphics.rs:11:18
   |
11 |     buffer: [u8; WIDTH as usize * HEIGHT as usize / 8],
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `400_usize * 300_usize`, which would overflow

error[E0080]: evaluation of constant value failed
  --> /home/jonathan/.cargo/registry/src/github.com-1ecc6299db9ec823/epd-waveshare-0.5.0/src/epd5in65f/graphics.rs:11:18
   |
11 |     buffer: [u8; WIDTH as usize * HEIGHT as usize / 2],
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `600_usize * 448_usize`, which would overflow

error[E0080]: evaluation of constant value failed
  --> /home/jonathan/.cargo/registry/src/github.com-1ecc6299db9ec823/epd-waveshare-0.5.0/src/epd7in5/graphics.rs:11:18
   |
11 |     buffer: [u8; WIDTH as usize * HEIGHT as usize / 8],
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `640_usize * 384_usize`, which would overflow

error[E0080]: evaluation of constant value failed
  --> /home/jonathan/.cargo/registry/src/github.com-1ecc6299db9ec823/epd-waveshare-0.5.0/src/epd7in5_hd/graphics.rs:11:18
   |
11 |     buffer: [u8; WIDTH as usize * HEIGHT as usize / 8],
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `880_usize * 528_usize`, which would overflow

error[E0080]: evaluation of constant value failed
  --> /home/jonathan/.cargo/registry/src/github.com-1ecc6299db9ec823/epd-waveshare-0.5.0/src/epd7in5_v2/graphics.rs:11:18
   |
11 |     buffer: [u8; WIDTH as usize * HEIGHT as usize / 8],
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `800_usize * 480_usize`, which would overflow

For more information about this error, try `rustc --explain E0080`.
error: could not compile `epd-waveshare` due to 5 previous errors
# Cargo.toml
[dependencies]
ufmt = "0.1.0"
crc = "3.0.1"
panic-halt = "0.2.0"
embedded-graphics = "0.7.1"
epd-waveshare = "0.5.0"

[dependencies.arduino-hal]
git = "https://github.com/rahix/avr-hal"
rev = "4c9c44c314eb061ee20556ef10d45dea36e75ee4"
features = ["arduino-nano"]

[dependencies.avr-device]
version = "0.5" 
$ rustup override set nightly
info: using existing install for 'nightly-x86_64-unknown-linux-gnu'
info: override toolchain for '/home/jonathan/Documents/Programming/Git/schalter-lampen' set to 'nightly-x86_64-unknown-linux-gnu'

  nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.69.0-nightly (246eae2fa 2023-02-21)
caemor commented 1 year ago

I assume you use an 16-bit avr architecture? Disabling default features removes the graphics parts, but I think that can be fixed by dividing the width by 8 first. But I need to check if the width is always dividable by eight.

tippfehlr commented 1 year ago

Sorry, I gave no context. The target is the Atmega 328P (Arduino Micro) and the Buffer does not fit in memory in the first place.

But why is an extra buffer in RAM used? I wrote an implementation where I implement the DrawTarget trait so that the image is written directly into the display's buffer. (That could be slower of course, I haven't tested it yet)

caemor commented 1 year ago

Its to change partial things of the full image, e.g. if you have a clock in one corner or similar things but the display doesn't allow partial updates. But yeah for the same reason as yours its an optional feature, although enabled by default

ldicarlo commented 11 months ago

Oh, do you mean that some code would change this pub const WIDTH: u32 = 800; ? I am not expert enough in Rust and macros, so I just assumed that this literal would never change.

tippfehlr commented 11 months ago

the dimensions are defined once for each display size (but don’t change).