antoyo / relm

Idiomatic, GTK+-based, GUI library, inspired by Elm, written in Rust
MIT License
2.42k stars 79 forks source link

Fix tree-view example on Windows #217

Closed Ace4896 closed 4 years ago

Ace4896 commented 4 years ago

Was trying out some of the examples and found that the tree-view example always crashed because of UNC paths (e.g. \\\\?\\C:\\projects\\3rdparty). I've used the dunce crate to handle removal of the \\\\?\\ prefix on Windows, without changing functionality for non-Windows platforms.

Strangely enough, before this change, it works when loading the application (as I can see all the files), but then crashes once trying to move to another directory.

antoyo commented 4 years ago

What do you mean by crash? It panics, segfaults?

Ace4896 commented 4 years ago

Sorry, I meant panic. It happens when any directory other than .. is selected:

".." selected
".git/" selected
thread 'main' panicked at 'create_and_fill_model failed: Os { code: 123, kind: Other, message: "The filename, directory name, or volume label syntax is incorrect." }', src\libcore\result.rs:1165:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
antoyo commented 4 years ago

Can you post the complete backtrace please? I wonder if there's another way to fix this.

Ace4896 commented 4 years ago

Here's the backtrace with RUST_BACKTRACE=full:

"examples/" selected
thread 'main' panicked at 'create_and_fill_model failed: Os { code: 123, kind: Other, message: "The filename, directory name, or volume label syntax is incorrect." }', src\libcore\result.rs:1165:5
stack backtrace:
   0:     0x7ff6de504079 - backtrace::backtrace::trace_unsynchronized
                               at C:\Users\VssAdministrator\.cargo\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.40\src\backtrace\mod.rs:66
   1:     0x7ff6de504079 - std::sys_common::backtrace::_print_fmt
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\/src\libstd\sys_common\backtrace.rs:77
   2:     0x7ff6de504079 - std::sys_common::backtrace::_print::{{impl}}::fmt
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\/src\libstd\sys_common\backtrace.rs:61
   3:     0x7ff6de514fbb - core::fmt::write
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\/src\libcore\fmt\mod.rs:1028
   4:     0x7ff6de501414 - std::io::Write::write_fmt<std::sys::windows::stdio::Stderr>
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\/src\libstd\io\mod.rs:1412
   5:     0x7ff6de506979 - std::sys_common::backtrace::_print
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\/src\libstd\sys_common\backtrace.rs:65
   6:     0x7ff6de506979 - std::sys_common::backtrace::print
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\/src\libstd\sys_common\backtrace.rs:50
   7:     0x7ff6de506979 - std::panicking::default_hook::{{closure}}
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\/src\libstd\panicking.rs:188
   8:     0x7ff6de5065cc - std::panicking::default_hook
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\/src\libstd\panicking.rs:205
   9:     0x7ff6de5070ac - std::panicking::rust_panic_with_hook
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\/src\libstd\panicking.rs:464
  10:     0x7ff6de506c20 - std::panicking::continue_panic_fmt
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\/src\libstd\panicking.rs:373
  11:     0x7ff6de506b09 - std::panicking::rust_begin_panic
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\/src\libstd\panicking.rs:302
  12:     0x7ff6de51280d - core::panicking::panic_fmt
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\/src\libcore\panicking.rs:139
  13:     0x7ff6de51290f - core::result::unwrap_failed
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\/src\libcore\result.rs:1165
  14:     0x7ff6de4d2b05 - core::result::Result<gtk::auto::list_store::ListStore, std::io::error::Error>::expect<gtk::auto::list_store::ListStore,std::io::error::Error>
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\src\libcore\result.rs:960
  15:     0x7ff6de4dc0ae - tree_view::{{impl}}::update
                               at C:\Users\Jon\Documents\Repositories\GitHub\relm\upstream\relm-examples\examples\tree-view.rs:109
  16:     0x7ff6de4e2def - relm::state::update_component<tree_view::Win>
                               at C:\Users\Jon\Documents\Repositories\GitHub\relm\upstream\src\state\mod.rs:164
  17:     0x7ff6de4e2c54 - relm::state::init_component::{{closure}}<tree_view::Win>
                               at C:\Users\Jon\Documents\Repositories\GitHub\relm\upstream\src\state\mod.rs:147
  18:     0x7ff6de4dda46 - alloc::boxed::{{impl}}::call_mut<(tree_view::Msg),FnMut<(tree_view::Msg)>>
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\src\liballoc\boxed.rs:949
  19:     0x7ff6de4e0625 - relm::core::{{impl}}::dispatch<tree_view::Msg>
                               at C:\Users\Jon\Documents\Repositories\GitHub\relm\upstream\src\core\mod.rs:149
  20:     0x7ff6de4da7a0 - relm::core::source::dispatch<relm::core::SourceData<tree_view::Msg>>
                               at C:\Users\Jon\Documents\Repositories\GitHub\relm\upstream\src\core\source.rs:74
  21:     0x7ffb0e415ae6 - g_main_dispatch
                               at C:\Users\Jon\vcpkg\buildtrees\glib\src\2.52.3-34a15219ec\glib\gmain.c:3234
  22:     0x7ffb0e413e34 - g_main_context_dispatch
                               at C:\Users\Jon\vcpkg\buildtrees\glib\src\2.52.3-34a15219ec\glib\gmain.c:3899
  23:     0x7ffb0e413e34 - g_main_context_iterate
                               at C:\Users\Jon\vcpkg\buildtrees\glib\src\2.52.3-34a15219ec\glib\gmain.c:3972
  24:     0x7ffb0e4160c5 - g_main_loop_run
                               at C:\Users\Jon\vcpkg\buildtrees\glib\src\2.52.3-34a15219ec\glib\gmain.c:4168
  25:     0x7ffb0ad00f6a - gtk_main
                               at C:\Users\Jon\vcpkg\buildtrees\gtk\src\gtk+-3-b723a7b846\gtk\gtkmain.c:1322
  26:     0x7ff6de4e684c - gtk::auto::functions::main
                               at C:\Users\Jon\.cargo\registry\src\github.com-1ecc6299db9ec823\gtk-0.8.1\src\auto\functions.rs:314
  27:     0x7ff6de4d5f6a - relm::run<tree_view::Win>
                               at C:\Users\Jon\Documents\Repositories\GitHub\relm\upstream\src\lib.rs:335
  28:     0x7ff6de4e1d89 - relm::widget::Widget::run<tree_view::Win>
                               at C:\Users\Jon\Documents\Repositories\GitHub\relm\upstream\src\widget.rs:64
  29:     0x7ff6de4dd4e9 - tree_view::main
                               at C:\Users\Jon\Documents\Repositories\GitHub\relm\upstream\relm-examples\examples\tree-view.rs:195
  30:     0x7ff6de4d90e0 - std::rt::lang_start::{{closure}}<()>
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\src\libstd\rt.rs:61
  31:     0x7ff6de506af7 - std::rt::lang_start_internal::{{closure}}
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\/src\libstd\rt.rs:48
  32:     0x7ff6de506af7 - std::panicking::try::do_call<closure-0,i32>
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\/src\libstd\panicking.rs:287
  33:     0x7ff6de50a5b2 - panic_unwind::__rust_maybe_catch_panic
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\/src\libpanic_unwind\lib.rs:78
  34:     0x7ff6de5072d2 - std::panicking::try
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\/src\libstd\panicking.rs:265
  35:     0x7ff6de5072d2 - std::panic::catch_unwind
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\/src\libstd\panic.rs:396
  36:     0x7ff6de5072d2 - std::rt::lang_start_internal
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\/src\libstd\rt.rs:47
  37:     0x7ff6de4d90bb - std::rt::lang_start<()>
                               at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\src\libstd\rt.rs:61
  38:     0x7ff6de4dd5b0 - main
  39:     0x7ff6de517c24 - invoke_main
                               at d:\agent\_work\5\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  40:     0x7ff6de517c24 - __scrt_common_main_seh
                               at d:\agent\_work\5\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  41:     0x7ffb5ad27bd4 - BaseThreadInitThunk
  42:     0x7ffb5bc6ced1 - RtlUserThreadStart
error: process didn't exit successfully: `target\debug\examples\tree-view.exe` (exit code: 101)

Now that I think about it, the one causing it might be the mixed use of \ and / when joining the paths together; adding a dbg! line in create_and_fill_model gives this:

     Running `target\debug\examples\tree-view.exe`
[examples\tree-view.rs:169] dir_str = "\\\\?\\C:\\Users\\Jon\\Documents\\Repositories\\GitHub\\relm\\upstream\\relm-examples"
"examples/" selected
[examples\tree-view.rs:169] dir_str = "\\\\?\\C:\\Users\\Jon\\Documents\\Repositories\\GitHub\\relm\\upstream\\relm-examples\\examples/"
thread 'main' panicked at 'create_and_fill_model failed: Os { code: 123, kind: Other, message: "The filename, directory name, or volume label syntax is incorrect." }', src\libcore\result.rs:1165:5
stack backtrace:
   0:     0x7ff6552f5539 - backtrace::backtrace::trace_unsynchronized
                               at C:\Users\VssAdministrator\.cargo\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.40\src\backtrace\mod.rs:66
-- similar backtrace to the one posted above --
Ace4896 commented 4 years ago

Ah, yes it was because of the mixed use of \ and / - I'll push another commit which uses the correct path separator instead of what I've done here.

antoyo commented 4 years ago

Thanks.