Skip to content

I tried to launch the program with its window hidden on startup, but a fleeting window ghost always flashes briefly on screen #4643

Description

@404neko

Description

use eframe::egui;
use std::time::{Duration, Instant};

struct TestApp {
start_time: Instant,
window_shown: bool,
}

impl TestApp {
fn new(cc: &eframe::CreationContext<'_>) -> Self {
cc.egui_ctx
.send_viewport_cmd(egui::ViewportCommand::Visible(false));

    Self {
        start_time: Instant::now(),
        window_shown: false,
    }
}

}

impl eframe::App for TestApp {
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
let ctx = ui.ctx().clone();

    if !self.window_shown {
        ctx.request_repaint();
        ctx.send_viewport_cmd(egui::ViewportCommand::Visible(false));

        if self.start_time.elapsed() >= Duration::from_secs(2) {
            println!("[TestApp] 2 seconds elapsed! Sending ViewportCommand::Visible(true)");
            ctx.send_viewport_cmd(egui::ViewportCommand::Visible(true));
            self.window_shown = true;
        }
    }

    ui.heading("Hidden Window Test App");
    ui.label(format!(
        "Elapsed time since launch: {:.2} seconds",
        self.start_time.elapsed().as_secs_f64()
    ));
    if self.window_shown {
        ui.label("Status: Window is now VISIBLE!");
    } else {
        ui.label("Status: Window is currently HIDDEN...");
    }
}

}

fn main() -> Result<(), eframe::Error> {
let mut viewport = egui::ViewportBuilder::default()
.with_title("Hidden Window Test")
.with_inner_size([400.0, 300.0])
.with_visible(false);

let options = eframe::NativeOptions {
    viewport,
    ..Default::default()
};

eframe::run_native(
    "Hidden Window Test",
    options,
    Box::new(|cc| Ok(Box::new(TestApp::new(cc)))),
)

}

Here is the simplest code to replicate this bug

btw this is crate I am using

egui = { version = "0.34.1", default-features = false, features = ["default_fonts"] }
eframe = { version = "0.34.1", default-features = false, features = ["wgpu_no_default_features", "persistence"] }
wgpu = { version = "29.0.1", default-features = false, features = ["vulkan"] }

Windows version

Windows 11 [10.0.26200]

Winit version

v0.30.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    B - bugDang, that shouldn't have happenedDS - win32Affects the Win32/Windows backend

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions