turnage / valora

painting by functions
https://paytonturnage.gitbook.io/valora/
MIT License
703 stars 30 forks source link

Crash when drawing many Ngons per frame #42

Closed ErikNatanael closed 4 years ago

ErikNatanael commented 4 years ago

So continuing from my questions in #41 I tried replacing

canvas.move_to(w);
canvas.line_to(P2::new(w.x + 1., w.y));
canvas.stroke();

with

canvas.paint(Filled(Ngon::square(w, 1.)));

to see if it would be faster. Turns out that drawing 30 000 of those per frame causes the program to crash at runtime with the error message below while drawing a smaller number such as 1000 seems fine. In between it's kind of a grey area where it runs for a bit and then crashes.

thread 'main' panicked at 'attempt to subtract with overflow', /home/erik/.cargo/registry/src/github.com-1ecc6299db9ec823/lyon_tessellation-0.14.2/src/fixed.rs:245:33
stack backtrace:
   0:     0x55fee7d01434 - backtrace::backtrace::libunwind::trace::h65597d255cb1398b
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
   1:     0x55fee7d01434 - backtrace::backtrace::trace_unsynchronized::hd4f479d7150ec4a0
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
   2:     0x55fee7d01434 - std::sys_common::backtrace::_print_fmt::h015072984a2b172c
                               at src/libstd/sys_common/backtrace.rs:77
   3:     0x55fee7d01434 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h6df05d3335f32194
                               at src/libstd/sys_common/backtrace.rs:61
   4:     0x55fee7d22cac - core::fmt::write::h1f444f4312eb6c27
                               at src/libcore/fmt/mod.rs:1028
   5:     0x55fee7cfe797 - std::io::Write::write_fmt::h8d147888220078ef
                               at src/libstd/io/mod.rs:1412
   6:     0x55fee7d0396e - std::sys_common::backtrace::_print::h8a6df0fa81d6af62
                               at src/libstd/sys_common/backtrace.rs:65
   7:     0x55fee7d0396e - std::sys_common::backtrace::print::h6f05b4733407e509
                               at src/libstd/sys_common/backtrace.rs:50
   8:     0x55fee7d0396e - std::panicking::default_hook::{{closure}}::h0d0a23bd02315dd8
                               at src/libstd/panicking.rs:188
   9:     0x55fee7d03661 - std::panicking::default_hook::h8d15a9aecb4efac6
                               at src/libstd/panicking.rs:205
  10:     0x55fee7d0406b - std::panicking::rust_panic_with_hook::hbe174577402a475d
                               at src/libstd/panicking.rs:464
  11:     0x55fee7d03c0e - std::panicking::continue_panic_fmt::h4d855dad868accf3
                               at src/libstd/panicking.rs:373
  12:     0x55fee7d03af6 - rust_begin_unwind
                               at src/libstd/panicking.rs:302
  13:     0x55fee7d1fc1e - core::panicking::panic_fmt::hdeb7979ab6591473
                               at src/libcore/panicking.rs:139
  14:     0x55fee7d1fb6a - core::panicking::panic::hb5daa85c7c72fc62
                               at src/libcore/panicking.rs:70
  15:     0x55fee76faff3 - <lyon_tessellation::fixed::Fp32<F> as core::ops::arith::Sub>::sub::h0365ef83d4f26d9b
                               at /home/erik/.cargo/registry/src/github.com-1ecc6299db9ec823/lyon_tessellation-0.14.2/src/fixed.rs:245
  16:     0x55fee7704a32 - <euclid::point::Point2D<T,U> as core::ops::arith::Sub>::sub::h353125170f56b9de
                               at /home/erik/.cargo/registry/src/github.com-1ecc6299db9ec823/euclid-0.20.7/src/point.rs:242
  17:     0x55fee76cd2f8 - lyon_tessellation::path_fill::FillTessellator::tessellator_loop::h661aa92e0bd6972d
                               at /home/erik/.cargo/registry/src/github.com-1ecc6299db9ec823/lyon_tessellation-0.14.2/src/path_fill.rs:442
  18:     0x55fee76ccc90 - lyon_tessellation::path_fill::FillTessellator::tessellate_events::h27618a730fa9db59
                               at /home/erik/.cargo/registry/src/github.com-1ecc6299db9ec823/lyon_tessellation-0.14.2/src/path_fill.rs:357
  19:     0x55fee74020d4 - lyon_tessellation::path_fill::FillTessellator::tessellate_path::h22c5b42d131b2310
                               at /home/erik/.cargo/registry/src/github.com-1ecc6299db9ec823/lyon_tessellation-0.14.2/src/path_fill.rs:331
  20:     0x55fee73cb8e1 - valora::raster::raster_path::ha8ae8a0dca5ad91d
                               at /home/erik/.cargo/registry/src/github.com-1ecc6299db9ec823/valora-0.2.2/src/raster.rs:39
  21:     0x55fee7343425 - valora::gpu::Gpu::render::{{closure}}::h0e9c2fef0da63f13
                               at /home/erik/.cargo/registry/src/github.com-1ecc6299db9ec823/valora-0.2.2/src/gpu.rs:318
  22:     0x55fee738da04 - core::iter::traits::iterator::Iterator::try_fold::hd519ec48e0f60eb6
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14/src/libcore/iter/traits/iterator.rs:1709
  23:     0x55fee738bc7c - <core::iter::adapters::Peekable<I> as core::iter::traits::iterator::Iterator>::try_fold::hc94bff2d12d4e559
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14/src/libcore/iter/adapters/mod.rs:1319
  24:     0x55fee73413f2 - valora::gpu::Gpu::render::h05b2145fcb6aeb4b
                               at /home/erik/.cargo/registry/src/github.com-1ecc6299db9ec823/valora-0.2.2/src/gpu.rs:313
  25:     0x55fee73745c0 - valora::render::Renderer<F1,F2>::render_frame::h810aeb0df5a4959f
                               at /home/erik/.cargo/registry/src/github.com-1ecc6299db9ec823/valora-0.2.2/src/render.rs:143
  26:     0x55fee73757f0 - valora::render::Renderer<F1,F2>::render_frames::h910b1637c619f2cb
                               at /home/erik/.cargo/registry/src/github.com-1ecc6299db9ec823/valora-0.2.2/src/render.rs:103
  27:     0x55fee73b1523 - valora::run_fn::h9727d3813b4f0ba8
                               at /home/erik/.cargo/registry/src/github.com-1ecc6299db9ec823/valora-0.2.2/src/lib.rs:270
  28:     0x55fee73b0455 - valora::run::h1e8cc6d235cab1b6
                               at /home/erik/.cargo/registry/src/github.com-1ecc6299db9ec823/valora-0.2.2/src/lib.rs:288
  29:     0x55fee7333d48 - valora_test::main::hf6b039243421f43b
                               at src/main.rs:202
  30:     0x55fee739d450 - std::rt::lang_start::{{closure}}::h9c61bd9ce008c062
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14/src/libstd/rt.rs:61
  31:     0x55fee7d03a93 - std::rt::lang_start_internal::{{closure}}::h6ea535ec5c50fc3e
                               at src/libstd/rt.rs:48
  32:     0x55fee7d03a93 - std::panicking::try::do_call::h631c6408dfccc6f5
                               at src/libstd/panicking.rs:287
  33:     0x55fee7d07d8a - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:78
  34:     0x55fee7d0460d - std::panicking::try::hab539b2d1255d635
                               at src/libstd/panicking.rs:265
  35:     0x55fee7d0460d - std::panic::catch_unwind::hd5e0a26424bd7f34
                               at src/libstd/panic.rs:396
  36:     0x55fee7d0460d - std::rt::lang_start_internal::h3bdc4c7d98181bf9
                               at src/libstd/rt.rs:47
  37:     0x55fee739d429 - std::rt::lang_start::hbe8c4f9be752a9be
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14/src/libstd/rt.rs:61
  38:     0x55fee7333d8a - main
  39:     0x7fb171c5ab6b - __libc_start_main
  40:     0x55fee73331ca - _start
  41:                0x0 - <unknown>

Full code is in this repo: https://github.com/ErikNatanael/valora-dof-test (I really like your default command line interface btw!)

turnage commented 4 years ago

Lyon got a new more durable tessellator recently. I updated to that and could not reproduce the issue any more.