native-dialog-rs icon indicating copy to clipboard operation
native-dialog-rs copied to clipboard

doesn't work on windows when inside a panic_handler

Open xMAC94x opened this issue 5 years ago • 3 comments

    let default_hook = panic::take_hook();
    panic::set_hook(Box::new(move |panic_info| {
        let msg = "foobar"

        error!(
            "VOXYGEN HAS PANICKED\n\n{}\n\nBacktrace:\n{:?}",
            msg,
            backtrace::Backtrace::new(),
        );

        {
            use native_dialog::{Dialog, MessageAlert, MessageType};

            let mbox = || {
                MessageAlert {
                    title: "Voxygen has panicked",
                    //somehow `<` and `>` are invalid characters and cause the msg to get replaced
                    // by some generic text thus i replace them
                    text: &msg.replace('<', "[").replace('>', "]"),
                    typ: MessageType::Error,
                }
                .show()
                .unwrap()
            };

            #[cfg(target_os = "macos")]
            dispatch::Queue::main().sync(mbox);
            #[cfg(not(target_os = "macos"))]
            mbox();
        }

        default_hook(panic_info);
    }));

Hi, i found out the code doesnt seem to work on windows INSIDE a panic_handler. it works fine outside the handler. It also works in linux inside a panic_handler

xMAC94x avatar Sep 08 '20 17:09 xMAC94x

just a quick followup. We are switchitng to native-dialog in veloren: https://gitlab.com/veloren/veloren/-/merge_requests/1373 and i found that moving the MessageAlert into another thread seems to work. I wasn't able to reproduce a minimal scenario. For my test in paniced in voxygen/src/menu/main/client_init.rs:60 which resulted in it not working. moving it to a new thread seems to be a workaround. if you want check out the coding under windows and remove the thread spawn.

xMAC94x avatar Sep 08 '20 21:09 xMAC94x

I cannot reproduce the problem too. What is the specific behavior of "not working"? Is the dialog just not showing, or returning Result::Err?

balthild avatar Sep 09 '20 23:09 balthild

For reproduceability you can prob checkout 68168b0ae44debbdc6f3107c14874a50bf04cd3d and remove the thread spawn here: https://gitlab.com/veloren/veloren/-/merge_requests/1373/diffs?commit_id=68168b0ae44debbdc6f3107c14874a50bf04cd3d#4b0f39d36087ef74b645c8a4c9e7e1a9c79c935e_110_124

What i noticed was a windows sound, but no visual window poping up. The window only pops up when moved to a new thread.

xMAC94x avatar Sep 22 '20 12:09 xMAC94x