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

thread 'main' panicked at 'called Option::unwrap() on a None value' #1426

Closed
Misaka299 opened this issue Nov 23, 2020 · 5 comments · Fixed by #1575
Closed

thread 'main' panicked at 'called Option::unwrap() on a None value' #1426

Misaka299 opened this issue Nov 23, 2020 · 5 comments · Fixed by #1575
Labels
crash causes panic or segfault shell/win concerns the Windows backend

Comments

@Misaka299
Copy link

Misaka299 commented Nov 23, 2020

C:/Users/me/.cargo/bin/cargo.exe run --color=always --package figure_sauce --bin figure_sauce
    Finished dev [unoptimized + debuginfo] target(s) in 0.24s
     Running `target\debug\figure_sauce.exe`
DEBUG [druid::localization] available locales [], current en-US
DEBUG [druid::localization] resolved: [en-US]
DEBUG [druid_shell::platform::windows::window] dxgi factory pointer = 0x212e39d6980
DEBUG [druid_shell::platform::windows::window] 0x212e39f3650: desc = Some("NVIDIA GeForce GTX 965M"), vram = 4252762112
DEBUG [druid_shell::platform::windows::window] 0x212e39f3b00: desc = Some("Intel(R) HD Graphics 530"), vram = 134217728
DEBUG [druid_shell::platform::windows::window] 0x212e39a1ff0: desc = Some("Microsoft Basic Render Driver"), vram = 0
DEBUG [druid_shell::platform::windows::window] adapter = 0x212e39f3650
DEBUG [druid_shell::platform::windows::window] swap chain res = 0x0, pointer = 0x212e5902ed0
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', C:\Users\me\.cargo\git\checkouts\druid-f71533f3d81c0bc8\e677854\druid-shell\src\platform\windows\window.rs:366:46
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src\panicking.rs:483
   1: core::panicking::panic_fmt
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\core\src\panicking.rs:85
   2: core::panicking::panic
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\core\src\panicking.rs:50
   3: core::option::Option<mut piet_direct2d::d2d::DeviceContext*>::unwrap<mut piet_direct2d::d2d::DeviceContext*>
             at C:\Users\me\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\option.rs:383
   4: druid_shell::platform::windows::window::WndState::render
             at C:\Users\me\.cargo\git\checkouts\druid-f71533f3d81c0bc8\e677854\druid-shell\src\platform\windows\window.rs:366
   5: druid_shell::platform::windows::window::{{impl}}::window_proc::{{closure}}
             at C:\Users\me\.cargo\git\checkouts\druid-f71533f3d81c0bc8\e677854\druid-shell\src\platform\windows\window.rs:697
   6: druid_shell::platform::windows::window::MyWndProc::with_wnd_state<closure-3,tuple<>>
             at C:\Users\me\.cargo\git\checkouts\druid-f71533f3d81c0bc8\e677854\druid-shell\src\platform\windows\window.rs:422
   7: druid_shell::platform::windows::window::{{impl}}::window_proc
             at C:\Users\me\.cargo\git\checkouts\druid-f71533f3d81c0bc8\e677854\druid-shell\src\platform\windows\window.rs:681
   8: druid_shell::platform::windows::window::win_proc_dispatch
             at C:\Users\me\.cargo\git\checkouts\druid-f71533f3d81c0bc8\e677854\druid-shell\src\platform\windows\window.rs:1435
   9: CallWindowProcW
  10: DispatchMessageW
  11: IsWindowVisible
  12: KiUserCallbackDispatcher
  13: NtUserDispatchMessage
  14: DispatchMessageW
  15: InputFocusMonitorCreate
  16: InputFocusMonitorCreate
  17: TF_Notify
  18: TF_Notify
  19: TF_SetShowFloatingStatus
  20: TF_SetShowFloatingStatus
  21: TF_SetShowFloatingStatus
  22: TF_SetShowFloatingStatus
  23: SetInputScopes2
  24: SetInputScopes2
  25: SetInputScopes2
  26: TF_PostAllThreadMsg
  27: CtfImeSelectEx
  28: SetInputScopes2
  29: SetInputScopes2
  30: TF_SetShowFloatingStatus
  31: TF_SetShowFloatingStatus
  32: TF_SetShowFloatingStatus
  33: SetInputScopes2
  34: CtfImeProcessCicHotkey
  35: CtfImeProcessCicHotkey
  36: CtfImeAssociateFocus
  37: CtfImeAssociateFocus
  38: CtfImeAssociateFocus
  39: ImmSetActiveContext
  40: GetWindow
  41: GetWindowRgnBox
  42: GetDlgItem
  43: GetDlgItem
  44: CallWindowProcW
  45: DispatchMessageW
  46: IsWindowVisible
  47: KiUserCallbackDispatcher
  48: NtUserShowWindow
  49: druid_shell::platform::windows::window::WindowHandle::show
             at C:\Users\me\.cargo\git\checkouts\druid-f71533f3d81c0bc8\e677854\druid-shell\src\platform\windows\window.rs:1511
  50: druid_shell::window::WindowHandle::show
             at C:\Users\me\.cargo\git\checkouts\druid-f71533f3d81c0bc8\e677854\druid-shell\src\window.rs:153
  51: druid::app::AppLauncher<u32>::launch<u32>
             at C:\Users\me\.cargo\git\checkouts\druid-f71533f3d81c0bc8\e677854\druid\src\app.rs:177
  52: figure_sauce::main
             at .\src\main.rs:7
  53: core::ops::function::FnOnce::call_once<fn() -> core::result::Result<tuple<>, druid_shell::error::Error>,tuple<>>
             at C:\Users\me\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:227
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: process didn't exit successfully: `target\debug\figure_sauce.exe` (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)

Process finished with exit code -1073740791 (0xC0000409)

This error message also appeared on my other computer, and it could not start normally. I am using examples.

use druid::widget::{Button, Flex, Label};
use druid::{AppLauncher, LocalizedString, PlatformError, Widget, WidgetExt, WindowDesc};

fn main() -> Result<(), PlatformError> {
    let main_window = WindowDesc::new(ui_builder);
    let data = 0_u32;
    AppLauncher::with_window(main_window)
        .use_simple_logger()
        .launch(data)
}

fn ui_builder() -> impl Widget<u32> {
    // The label text will be computed dynamically based on the current locale and count
    let text =
        LocalizedString::new("hello-counter").with_arg("count", |data: &u32, _env| (*data).into());
    let label = Label::new(text).padding(5.0).center();
    let button = Button::new("increment")
        .on_click(|_ctx, data, _env| *data += 1)
        .padding(5.0);

    Flex::column().with_child(label).with_child(button)
}
@cmyr
Copy link
Member

cmyr commented Nov 24, 2020

What version of windows are you running? It looks like we're failing to create a render target. @raphlinus would have a better understanding of what would cause that, I'm not as familiar with the windows backend.

@cmyr cmyr added crash causes panic or segfault shell/win concerns the Windows backend labels Nov 24, 2020
@rhzk
Copy link
Collaborator

rhzk commented Nov 25, 2020

I suspect what happens here is that he ends up getting a WM_PAINT message before WM_SIZE on startup,

Inside WM_PAINT render() is called but the render_target is not yet created, this happens inside WM_SIZE with rebuild_render_target() call.

Adding a state.rebuild_render_target(&self.d2d_factory, scale); towards the end in WM_CREATE might solve this problem.

Edit: Try this branch and let me know if it solved the problem: https://github.com/rhzk/druid/tree/1426

@rhzk rhzk added the S-waiting-on-author waits for changes from the submitter label Dec 2, 2020
@Misaka299
Copy link
Author

  • [ ]

@Misaka299 Misaka299 reopened this Dec 7, 2020
@Misaka299
Copy link
Author

Uploading QQ图片20201207160708.png…

@Perlmint
Copy link
Contributor

Perlmint commented Feb 3, 2021

I suspect what happens here is that he ends up getting a WM_PAINT message before WM_SIZE on startup,

Inside WM_PAINT render() is called but the render_target is not yet created, this happens inside WM_SIZE with rebuild_render_target() call.

Adding a state.rebuild_render_target(&self.d2d_factory, scale); towards the end in WM_CREATE might solve this problem.

Edit: Try this branch and let me know if it solved the problem: https://github.com/rhzk/druid/tree/1426

I also encountered the same error.

As @rhzk suspected, WM_SIZE has not occurred before WM_PAINT.

I tried on the master branch. Below patch is worked for me.

--- a/druid-shell/src/platform/windows/window.rs
+++ b/druid-shell/src/platform/windows/window.rs
@@ -663,6 +663,10 @@ impl WndProc for MyWndProc {

                     let handle = self.handle.borrow().to_owned();
                     state.handler.connect(&handle.into());
+
+                    if let Err(e) = state.rebuild_render_target(&self.d2d_factory, scale) {
+                        log::error!("error building render target: {}", e);
+                    }
                 }
                 Some(0)
             }

As a workaround, Giving size with WindowDesc::window_size before launching the app is also worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash causes panic or segfault shell/win concerns the Windows backend
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants