hecrj / coffee

An opinionated 2D game engine for Rust
https://docs.rs/coffee
MIT License
1.09k stars 55 forks source link

Game crashes when minimizing #86

Open Songtronix opened 5 years ago

Songtronix commented 5 years ago

OS: Win10 Version: crates.io

Just minimized the example project (opengl + debug feat.) and it crashed with the following error:

thread 'main' panicked at 'The left corner must not be equal to the right corner.', C:\Users\USER\.cargo\registry\src\github.com-1ecc6299db9ec823\nalgebra-0.18.0\src\geometry\orthographic.rs:622:9
stack backtrace:
   0: backtrace::backtrace::trace_unsynchronized
             at C:\Users\VssAdministrator\.cargo\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.29\src\backtrace\mod.rs:66
   1: std::sys_common::backtrace::_print
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\/src\libstd\sys_common\backtrace.rs:47
   2: std::sys_common::backtrace::print
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\/src\libstd\sys_common\backtrace.rs:36
   3: std::panicking::default_hook::{{closure}}
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\/src\libstd\panicking.rs:200
   4: std::panicking::default_hook
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\/src\libstd\panicking.rs:214
   5: std::panicking::rust_panic_with_hook
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\/src\libstd\panicking.rs:477
   6: std::panicking::begin_panic<str*>
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\src\libstd\panicking.rs:411
   7: nalgebra::geometry::orthographic::Orthographic3<f32>::new
             at C:\Users\USER\.cargo\registry\src\github.com-1ecc6299db9ec823\nalgebra-0.18.0\src\geometry\orthographic.rs:0
   8: nalgebra::base::matrix::Matrix<f32, nalgebra::base::dimension::U4, nalgebra::base::dimension::U4, nalgebra::base::array_storage::ArrayStorage<f32, nalgebra::base::dimension::U4, nalgebra::base::dimension::U4>>::new_orthographic
             at C:\Users\USER\.cargo\registry\src\github.com-1ecc6299db9ec823\nalgebra-0.18.0\src\base\cg.rs:118
   9: coffee::graphics::transformation::Transformation::orthographic
             at C:\Users\USER\.cargo\registry\src\github.com-1ecc6299db9ec823\coffee-0.3.1\src\graphics\transformation.rs:30
  10: coffee::graphics::target::Target::new
             at C:\Users\USER\.cargo\registry\src\github.com-1ecc6299db9ec823\coffee-0.3.1\src\graphics\target.rs:32
  11: coffee::graphics::window::frame::Frame::as_target
             at C:\Users\USER\.cargo\registry\src\github.com-1ecc6299db9ec823\coffee-0.3.1\src\graphics\window\frame.rs:55
  12: coffee::graphics::window::frame::Frame::clear
             at C:\Users\USER\.cargo\registry\src\github.com-1ecc6299db9ec823\coffee-0.3.1\src\graphics\window\frame.rs:62
  13: example::gui::{{impl}}::draw
             at .\client\src\gui.rs:29
  14: coffee::game::Game::run<example::gui::MyGame>
             at C:\Users\USER\.cargo\registry\src\github.com-1ecc6299db9ec823\coffee-0.3.1\src\game.rs:217
  15: example::gui::start
             at .\client\src\gui.rs:6
  16: example::main
             at .\client\src\main.rs:4
  17: std::rt::lang_start::{{closure}}<()>
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\src\libstd\rt.rs:64
  18: std::rt::lang_start_internal::{{closure}}
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\/src\libstd\rt.rs:49
  19: std::panicking::try::do_call<closure,i32>
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\/src\libstd\panicking.rs:296
  20: panic_unwind::__rust_maybe_catch_panic
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\/src\libpanic_unwind\lib.rs:82
  21: std::panicking::try
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\/src\libstd\panicking.rs:275
  22: std::panic::catch_unwind
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\/src\libstd\panic.rs:394
  23: std::rt::lang_start_internal
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\/src\libstd\rt.rs:48
  24: main
  25: invoke_main
             at d:\agent\_work\3\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  26: __scrt_common_main_seh
             at d:\agent\_work\3\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  27: BaseThreadInitThunk
  28: RtlUserThreadStart
error: process didn't exit successfully: `target\debug\example.exe` (exit code: 101)

I guess this can be solved in here.

hecrj commented 5 years ago

Thanks for the report!

I am guessing this may be happening because winit or glutin is reporting the window dimensions as 0 when minimized.

Let's wait until winit releases a stable 0.20.0 and then we can apply the fix in #62. We should probably avoid calling draw when the window is minimized.