Skip to content

Thread panic message to stderr kills windowed mode Windows binaries #25643

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

Closed
rsaarelm opened this issue May 20, 2015 · 4 comments
Closed

Thread panic message to stderr kills windowed mode Windows binaries #25643

rsaarelm opened this issue May 20, 2015 · 4 comments
Labels
O-windows Operating system: Windows

Comments

@rsaarelm
Copy link

Windows binaries built with the -mwindows linker flag can't have any output to stdout or stderr in them or Windows will instantly terminate the program. I want to have windowed mode binaries for GUI applications, since without the windowed mode flag the binary will spawn a visible console window in addition to the GUI window every time it's run.

Panicing threads seem to cause an unconditional print to stderr. I'm trying to write a panic handler that will pop up a Windows message dialog instead of printing to stdout when the program terminates with a panic, but currently can't do that because windowed mode programs die at the point of the panic and the handler is never reached.

To test this, write panic.rs:

fn f() { panic!("This kills the Windows"); }

fn main() {
    match std::thread::Builder::new().spawn(f).unwrap().join() {
        Err(_) => { std::fs::File::create("panic_log.txt"); }
        _ => {}
    }
}

Build it with rustc -C link-args=-mwindows panic.rs. Then run panic.exe from the Windows explorer. The program terminates and the panic_log.txt file never shows up. (It does seem to work if you run it from the Command Prompt, but end users will be clicking an icon.)

@nagisa
Copy link
Member

nagisa commented May 20, 2015

#24099

@Diggsey
Copy link
Contributor

Diggsey commented May 21, 2015

rust-lang/rfcs#1100

@steveklabnik steveklabnik added the O-windows Operating system: Windows label May 21, 2015
@retep998
Copy link
Member

rust-lang/rfcs#1014 would fix this issue.

@alexcrichton
Copy link
Member

The linked issues by @nagisa, @Diggsey, and @retep998 I believe all cover our bases pretty well here, so I'm going to close this as a dupe of them. Thanks regardless for the report though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-windows Operating system: Windows
Projects
None yet
Development

No branches or pull requests

6 participants