From 842565c5def7b446a509f13c31d98d6735ff6777 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Fri, 3 Jul 2026 13:42:55 -0700 Subject: better managing of state Force-Push: yes Change-Id: I5a6982e0f8d06ff173fd31948dbd0f579b3d38ba --- flake.nix | 4 ++-- src/main.rs | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index 5a6b93f..702c355 100644 --- a/flake.nix +++ b/flake.nix @@ -25,8 +25,6 @@ libxcursor libxi libxkbcommon - # mesa - # wayland vulkan-loader ]; in { @@ -38,6 +36,8 @@ nativeBuildInputs = with pkgs; [ autoPatchelfHook ]; }).overrideAttrs { + # This needs to apply only to the top-level derivation, not to the + # dependencies. preFixup = '' patchelf --add-needed libxkbcommon-x11.so \ --add-needed libvulkan.so.1 \ diff --git a/src/main.rs b/src/main.rs index 4fcb01c..e45e49f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -95,17 +95,17 @@ fn ignore_errors(mut body: impl FnMut() -> Result<()>) -> () { struct Surreality { + window: OnceCell, entry: OnceCell, instance: OnceCell, - window: OnceCell, } impl Surreality { fn new() -> Self { Surreality { + window: OnceCell::new(), entry: OnceCell::new(), instance: OnceCell::new(), - window: OnceCell::new(), } } @@ -116,12 +116,17 @@ impl Surreality { .with_inner_size(LogicalSize::new(1024, 768)); let window: Window = event_loop.create_window(window_attributes)?; let _ = self.window.set(window); + } + if self.entry.get().is_none() { #[allow(unsafe_code)] let loader = unsafe { LibloadingLoader::new(LIBRARY)? }; #[allow(unsafe_code)] let entry = unsafe { Entry::new(loader)? }; + let _ = self.entry.set(entry); + } + if self.instance.get().is_none() { let application_info = ApplicationInfo::builder() .application_name(b"Surreality\0") .application_version(vk::make_version(1, 0, 0)) @@ -139,8 +144,11 @@ impl Surreality { #[allow(unsafe_code)] let instance = unsafe { + let entry = self.entry.get().unwrap(); entry.create_instance(&instance_create_info, None)? }; + + let _ = self.instance.set(instance); } Ok(()) -- cgit 1.4.1