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

Panic in quad_gl on breaking the game loop #681

Open
PEZ opened this issue Dec 29, 2023 · 0 comments · May be fixed by #814
Open

Panic in quad_gl on breaking the game loop #681

PEZ opened this issue Dec 29, 2023 · 0 comments · May be fixed by #814

Comments

@PEZ
Copy link

PEZ commented Dec 29, 2023

Hi! Thanks for providing Macroquad. I have had a lot of fun with it he last few days.

I run into a strange panic issue when exiting the game loop after having rendered a glsl shader pair. I may be holding it wrong, but anyway. This is the smallest reproduction I can figure out how to make:

use macroquad::prelude::*;

const FRAGMENT_SHADER: &str = "#version 100
void main() { }
";

const VERTEX_SHADER: &str = "#version 100
void main() { }
";

#[macroquad::main("¡Viva la libertad, CARAJO!")]
async fn main() {
    let render_target = render_target(320, 150);
    let material = load_material(
        ShaderSource::Glsl {
            vertex: VERTEX_SHADER,
            fragment: FRAGMENT_SHADER,
        },
        MaterialParams {
            ..Default::default()
        },
    )
    .unwrap();

    loop {
        clear_background(BLACK);

        gl_use_material(&material);
        draw_texture_ex(
            &render_target.texture,
            0.,
            0.,
            WHITE,
            DrawTextureParams {
                dest_size: Some(vec2(screen_width(), screen_height())),
                ..Default::default()
            },
        );
        gl_use_default_material();

        if is_key_pressed(KeyCode::Escape) {
            break;
        }

        next_frame().await;
    }
}

It seems to matter if I call draw_texture_ex() or not, because removing it, I do not get the panic.

To check that it is happening on latest macroquad. I'm using a freshly cloned local repo with master checked out.

To reproduce

  1. cargo run
  2. Press escape
  • Expected: The program exits cleanly
  • Actual: There's a panic:
    thread 'main' panicked at /Users/pez/Projects/macroquad/src/quad_gl.rs:581:40:
    called `Option::unwrap()` on a `None` value
    
stack backtrace:
   0:        0x100fb51f8 - std::backtrace_rs::backtrace::libunwind::trace::hf755a955ad018943
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:        0x100fb51f8 - std::backtrace_rs::backtrace::trace_unsynchronized::hde69ab8e2b667964
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:        0x100fb51f8 - std::sys_common::backtrace::_print_fmt::hf6c414569af631f5
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/sys_common/backtrace.rs:67:5
   3:        0x100fb51f8 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h0524bd1b527203b8
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/sys_common/backtrace.rs:44:22
   4:        0x100fca9d4 - core::fmt::rt::Argument::fmt::ha0532872e39381ee
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/fmt/rt.rs:138:9
   5:        0x100fca9d4 - core::fmt::write::h74be1333b0a6ddea
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/fmt/mod.rs:1114:21
   6:        0x100fb3430 - std::io::Write::write_fmt::h6c011b665b2d7d4b
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/io/mod.rs:1763:15
   7:        0x100fb5038 - std::sys_common::backtrace::_print::hcc60dadc0e4df78f
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/sys_common/backtrace.rs:47:5
   8:        0x100fb5038 - std::sys_common::backtrace::print::he25ff7dac6402434
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/sys_common/backtrace.rs:34:9
   9:        0x100fb6554 - std::panicking::default_hook::{{closure}}::h41763ba018b93bf7
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/panicking.rs:272:22
  10:        0x100fb626c - std::panicking::default_hook::h017c44660373840e
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/panicking.rs:292:9
  11:        0x100fb6a98 - std::panicking::rust_panic_with_hook::h221a0baf52ecd48a
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/panicking.rs:731:13
  12:        0x100fb6960 - std::panicking::begin_panic_handler::{{closure}}::h18b661cf0f97a414
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/panicking.rs:601:13
  13:        0x100fb5684 - std::sys_common::backtrace::__rust_end_short_backtrace::h4f4b2ffab2311217
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/sys_common/backtrace.rs:170:18
  14:        0x100fb670c - rust_begin_unwind
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/panicking.rs:597:5
  15:        0x100fd6e28 - core::panicking::panic_fmt::hd6070cd222575be5
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/panicking.rs:72:14
  16:        0x100fd6e9c - core::panicking::panic::h73d0202ad9ee694f
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/panicking.rs:127:5
  17:        0x100ef3204 - core::option::Option<T>::unwrap::h08944aaf3b8c61d9
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/option.rs:935:21
  18:        0x100ec96d0 - macroquad::quad_gl::PipelinesStorage::get_quad_pipeline_mut::h1cee76272d135a2f
                               at /Users/pez/Projects/macroquad/src/quad_gl.rs:581:9
  19:        0x100eca678 - macroquad::quad_gl::QuadGl::draw::h54338d4641d16da1
                               at /Users/pez/Projects/macroquad/src/quad_gl.rs:742:28
  20:        0x100ecf2ac - macroquad::Context::perform_render_passes::h024738a5239f14e9
                               at /Users/pez/Projects/macroquad/src/lib.rs:451:9
  21:        0x100ef0010 - macroquad::camera::set_camera::hee71a6274000a0bf
                               at /Users/pez/Projects/macroquad/src/camera.rs:244:5
  22:        0x100ee0658 - macroquad::experimental::scene::Scene::update::hb2c53953ec63138d
                               at /Users/pez/Projects/macroquad/src/experimental/scene.rs:545:17
  23:        0x100ee0dc4 - macroquad::experimental::scene::update::hb07619d1eb860d5e
                               at /Users/pez/Projects/macroquad/src/experimental/scene.rs:657:5
  24:        0x100ecef4c - macroquad::Context::end_frame::he7565b753c9fb120
                               at /Users/pez/Projects/macroquad/src/lib.rs:387:9
  25:        0x100ecfe38 - <macroquad::Stage as miniquad::event::EventHandler>::draw::h69473899255147d8
                               at /Users/pez/Projects/macroquad/src/lib.rs:709:17
  26:        0x100f59cec - miniquad::native::macos::define_opengl_view_class::draw_rect::h3e5dc763fa467705
                               at /Users/pez/.cargo/registry/src/index.crates.io-6f17d22bba15001f/miniquad-0.4.0-alpha.10/src/native/macos.rs:659:13
  27:        0x18b85080c - <unknown>
  28:        0x18f9cf614 - <unknown>
  29:        0x18fb52c70 - <unknown>
  30:        0x18f9b2658 - <unknown>
  31:        0x18b239298 - <unknown>
  32:        0x18bbd73c8 - <unknown>
  33:        0x1879370cc - <unknown>
  34:        0x187936fb8 - <unknown>
  35:        0x1879365e8 - <unknown>
  36:        0x187935c2c - <unknown>
  37:        0x191e8e448 - <unknown>
  38:        0x191e8e284 - <unknown>
  39:        0x191e8dfdc - <unknown>
  40:        0x18b110f90 - <unknown>
  41:        0x18b8e4b94 - <unknown>
  42:        0x18b10443c - <unknown>
  43:        0x100f5ee44 - <() as objc::message::MessageArguments>::invoke::h01b87ae8605e22a1
                               at /Users/pez/.cargo/registry/src/index.crates.io-6f17d22bba15001f/objc-0.2.7/src/message/mod.rs:128:17
  44:        0x100f863f0 - objc::message::platform::send_unverified::hba0b1b6da4ee70c6
                               at /Users/pez/.cargo/registry/src/index.crates.io-6f17d22bba15001f/objc-0.2.7/src/message/apple/mod.rs:27:9
  45:        0x100e96ecc - objc::message::send_message::h8f8c9d325d2a377a
                               at /Users/pez/.cargo/registry/src/index.crates.io-6f17d22bba15001f/objc-0.2.7/src/message/mod.rs:178:5
  46:        0x100e96ecc - miniquad::native::macos::run::h6084494873dd6c2e
                               at /Users/pez/.cargo/registry/src/index.crates.io-6f17d22bba15001f/miniquad-0.4.0-alpha.10/src/native/macos.rs:981:14
  47:        0x100e997a4 - miniquad::start::hbdb5aca556025476
                               at /Users/pez/.cargo/registry/src/index.crates.io-6f17d22bba15001f/miniquad-0.4.0-alpha.10/src/lib.rs:290:9
  48:        0x100e97e3c - macroquad::Window::from_config::h3a4f910c770668c7
                               at /Users/pez/Projects/macroquad/src/lib.rs:764:9
  49:        0x100e98228 - macroquad::Window::new::hf383a8b7cb52cd5d
                               at /Users/pez/Projects/macroquad/src/lib.rs:753:9
  50:        0x100e924a8 - macroquad_gl_unwind_panic::main::h323a7f317dc72a39
                               at /Users/pez/Projects/tests/macroquad-gl-unwind-panic/src/main.rs:11:1
  51:        0x100e98f34 - core::ops::function::FnOnce::call_once::h3a08557b5db96c39
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/ops/function.rs:250:5
  52:        0x100e98ec8 - std::sys_common::backtrace::__rust_begin_short_backtrace::he5ad8b9e403bb769
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/sys_common/backtrace.rs:154:18
  53:        0x100e923a0 - std::rt::lang_start::{{closure}}::h397a925b4fa5bef3
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/rt.rs:166:18
  54:        0x100fb1138 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h44482c562109b08c
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/ops/function.rs:284:13
  55:        0x100fb1138 - std::panicking::try::do_call::h627d61d518625eaf
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/panicking.rs:504:40
  56:        0x100fb1138 - std::panicking::try::h487b8df834773e7d
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/panicking.rs:468:19
  57:        0x100fb1138 - std::panic::catch_unwind::h5d4366c6f71d3443
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/panic.rs:142:14
  58:        0x100fb1138 - std::rt::lang_start_internal::{{closure}}::h749338e1cc06c4f7
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/rt.rs:148:48
  59:        0x100fb1138 - std::panicking::try::do_call::h2098bd254e5cae95
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/panicking.rs:504:40
  60:        0x100fb1138 - std::panicking::try::h7bfd8a0246bca0f8
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/panicking.rs:468:19
  61:        0x100fb1138 - std::panic::catch_unwind::h6da51257cc975c65
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/panic.rs:142:14
  62:        0x100fb1138 - std::rt::lang_start_internal::h5f00c09289a72e67
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/rt.rs:148:20
  63:        0x100e9236c - std::rt::lang_start::hb2750eb1c5b2e293
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/rt.rs:165:17
  64:        0x100e924e0 - _main

Cheers!

@InnocentusLime InnocentusLime linked a pull request Sep 21, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant