Skip to content

When an immediate viewport is displayed, the cache will return None. #5441

@zhatuokun

Description

@zhatuokun

Describe the bug
Cache works well in general, but when you have an immediate viewport, it will return None.

To Reproduce
Steps to reproduce the behavior:

  1. add master branch to Cargo.toml.
egui = { git = "https://github.com/emilk/egui", branch = "master" }
eframe = { git = "https://github.com/emilk/egui", branch = "master" }
  1. run this code.
type MyPublisher = egui::cache::FramePublisher<String, u32>;

fn main() -> eframe::Result {
    eframe::run_simple_native("Example", eframe::NativeOptions::default(), |ctx, _| {
        let key = String::from("key");
        let value = ctx.memory_mut(|m| m.caches.cache::<MyPublisher>().get(&key).copied());
        println!("value: {value:?}");
        ctx.memory_mut(|m| m.caches.cache::<MyPublisher>().set(key, 0));

        // If I comment out the following code, everything will be fine.
        ctx.show_viewport_immediate(
            egui::ViewportId::from_hash_of("ExampleViewport"),
            Default::default(),
            |_, _| {},
        );
    })
}

Expected behavior
Even if immediate viewport is displayed, the cache should work properly.

Desktop (please complete the following information):

  • OS: Windows 11
  • Version: 23H2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is broken

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions