Rust-SDL2 / rust-sdl2

SDL2 bindings for Rust
MIT License
2.72k stars 467 forks source link

draw_rect() is drawing outside of bounds #1342

Open computermouth opened 11 months ago

computermouth commented 11 months ago

I have a couple snippets of code that are drawing rectangles:

cvs.set_draw_color(Color::RGB(0, 255, 0));
cvs.draw_rect(Rect::new(8, 8, 8, 8)).unwrap();

They all seem to be drawing the bottom-right pixel at the top left. Screenshot and system information below. Source is available here: https://github.com/computermouth/rustsdlsnake/blob/master/src/main.rs

2023-10-18--1697674325_151x112_scrot

Cargo.toml:

[package]
name = "rustsdl2snake"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.5"
sdl2 = "0.35.2"

rust:

$ rustup --version
rustup 1.26.0 (5af9b9484 2023-04-05)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.71.1 (eb26296b5 2023-08-03)`
$ rustc --version
rustc 1.71.1 (eb26296b5 2023-08-03)
$ cargo --version
cargo 1.71.1 (7f1d04c00 2023-07-29)

OS:

PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

SDL2:

$ dpkg -s libsdl2-dev
Package: libsdl2-dev
Status: install ok installed
Priority: optional
Section: libdevel
Installed-Size: 8738
Maintainer: Debian SDL packages maintainers <pkg-sdl-maintainers@lists.alioth.debian.org>
Architecture: amd64
Multi-Arch: same
Source: libsdl2
Version: 2.0.14+dfsg2-3+deb11u1
Replaces: libsdl-1.3-dev
Depends: libasound2-dev, libdbus-1-dev, libegl1-mesa-dev, libgl1-mesa-dev, libgles-dev, libglu1-mesa-dev, libibus-1.0-dev, libpulse-dev, libsdl2-2.0-0 (= 2.0.14+dfsg2-3+deb11u1), libsndio-dev, libudev-dev, libwayland-dev, libx11-dev, libxcursor-dev, libxext-dev, libxi-dev, libxinerama-dev, libxkbcommon-dev, libxrandr-dev, libxss-dev, libxt-dev, libxv-dev, libxxf86vm-dev, libc6 (>= 2.7), libgl1, libx11-6
Conflicts: libsdl-1.3-dev
Description: Simple DirectMedia Layer development files
 SDL is a library that allows programs portable low level access to a video
 framebuffer, audio output, mouse, and keyboard.
 .
 This package contains the files needed to compile and link programs which
 use SDL.
Homepage: https://www.libsdl.org/
computermouth commented 11 months ago

Confirmed that this doesn't happen with the same code on my system with c+sdl2, or rust+fermium(sdl2-bindings)

Cobrand commented 11 months ago

snake

Are you 100% sure the same SDL version is used in the other examples? When I'm running your example on my machine I get the screenshot above, which seems correct.

By the way, my SDL2 is on version 2.28.8, and I am on linux as well.