Skip to content

Negative input vector with instantiated Graphics struct in code causes panic! #1056

Open
@Kiel97

Description

@Kiel97

Hey! It is most likely more related to nightly's Rust build (rustc 1.90.0-nightly (11ad40bb8 2025-06-28)) than agb crate but at the moment this is a showstopper and you should be aware of it.

This happens when player presses either UP or LEFT buttons AND there is let mut gfx = gba.graphics.get(); in code. You don't have to show anything to make it panic. I found this bug today after updating Rust toolchain with rustup update command. Right now even Pong tutorial is crashing when pressing UP button.

Here's the stack

[ERROR] GBA Debug: [failed]
[INFO] GBA Debug: Stack trace: https://agbrs.dev/crash#5IBJDLJHD0Oe07005av1
[FATAL] GBA Debug: Error: panicked at /home/dyzio/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/agb-0.22.2/src/input.rs:38:18:
trying to construct an enum from an invalid value 0xffffffffffffffffffffffffffffffff

Here's the minimum example. Just clone agb's template and paste this code snippet.

#[agb::entry]
fn main(mut gba: agb::Gba) -> ! {
    let mut gfx = gba.graphics.get();

    let mut input = ButtonController::new();
    let mut v: Vector2D<i32> = vec2(16, 16);

    loop {
        input.update();

        // If `let mut gfx = gba.graphics.get();` is present in code, here program panics
        let dv = input.vector() as Vector2D<i32>;

        v += dv;

        // // This most likely doesn't have an impact on issue, that's why it's commented out
        // let mut frame = gfx.frame();
        // frame.commit();
        // agb::halt();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions